深入JVM关闭与关闭钩子

http://blog.csdn.net/dd864140130/article/details/49155179

package learnthread.closet;

import javax.xml.stream.events.StartDocument;

public class JVMHookTest {
    /**
     * 在jvm退出前会首先关闭钩子
     */
    public static void start() {
        System.out.println("jvm is start");
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                System.out.println("jvm hook is execute");
            }

        });
    }

    public static void main(String[] args) {
        start();
        System.out.println("The Application is doing something");

        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

 

posted @ 2016-03-02 15:46  程序猿进化之路  阅读(194)  评论(0)    收藏  举报