Is it possible to write a method that System.exit will call when you terminate a program?
Use Runtime.getRuntime().addShutdownHook(Thread).
Runtime.getRuntime().addShutdownHook(Thread)