ShutdownHook

来源:互联网 发布:淘宝搜索最多的关键词 编辑:程序博客网 时间:2024/04/27 21:47
  
public static void sd() throws Exception {
        Object f = new Object() {
            public void finalize() {
                System.out.println("Running finalize()");
            }
        };
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                System.out.println("Running Shutdown Hook");
            }
        });

        f = null;
        System.gc();

        System.out.println("Calling System.exit()");
        System.exit(0);
    }

System.gc() call finalize();
System.exit(0)  or process finished call shutdownHook;
原创粉丝点击