Category: Java API 使用

[JAVA] Runtime.getRuntime().addShutdownHook

Before jvm finishs, it will run the thread added to Runtime.getRuntime().addShutdownHook

good for watch dog

public void attachWatchDog() {
   Runtime.getRuntime().addShutdownHook(new Thread() {
      public void run() {
         System.out.println("your last chance before program terminated");
      }
    });
}
Tags :