Java examples for Java Virtual Machine:Utility
Determining When the Application Is About to Exit
public class Main { public void m() { // Register a shutdown thread Runtime.getRuntime().addShutdownHook(new Thread() { // This method is called during shutdown public void run() { // Do shutdown work ... }// w w w . ja va 2 s . com }); } }