Shut down hook

ReturnMethodSummary
voidaddShutdownHook(Thread hook)Registers a new virtual-machine shutdown hook.
booleanremoveShutdownHook(Thread hook)De-registers a previously-registered virtual-machine shutdown hook.

public class Main {
  public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();

    runtime.addShutdownHook(new Thread(){
      public void run(){
        System.out.println("Shut down");
        
      }
      
    });
  }
}

The output:


Shut down
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.