`

About ShutDownDemo

阅读更多
public class ShutdownDemo {
	public static void main(String[] args) throws Exception {

        // Create an Object with a finalize() method.
        Object f = new Object() {
            public void finalize() {
                System.out.println("Running finalize()");
            }
        };

        // Add a shutdownHook to the JVM
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                System.out.println("Running Shutdown Hook");
            }
        });

        // Unless the user puts -f (for "free") on the command line,
        // call System.exit while holding a reference to
        // Object f, which can therefore not be finalized().

        f = null;
        System.gc();

        System.out.println("Calling System.exit()");
        System.exit(0);
    }
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics