@@ -0,0 +1,701 @@
+package com.dw.lib.test;%0A%0Apublic class AddShutdownHookTest %7B%0A%0A%09static class Message extends Thread %7B%0A%0A%09%09public void run() %7B%0A%09%09%09System.out.println(%22Bye.%22);%0A%09%09%7D%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09try %7B%0A%0A%09%09%09// register Message as shutdown hook%0A%09%09%09Runtime.getRuntime().addShutdownHook(new Message());%0A%0A%09%09%09// print the state of the program%0A%09%09%09System.out.println(%22Program is starting...%22);%0A%0A%09%09%09// cause thread to sleep for 3 seconds%0A%09%09%09System.out.println(%22Waiting for 3 seconds...%22);%0A%09%09%09Thread.sleep(3000);%0A%0A%09%09%09// print that the program is closing%0A%09%09%09System.out.println(%22Program is closing...%22);%0A%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

add java shutdown hook