jdk/src/share/classes/java/io/DeleteOnExitHook.java
changeset 2277 445a331b4a8b
parent 2 90ce3da70b43
child 2703 acd4d6a53e3e
--- a/jdk/src/share/classes/java/io/DeleteOnExitHook.java	Mon Mar 09 09:56:58 2009 -0400
+++ b/jdk/src/share/classes/java/io/DeleteOnExitHook.java	Thu Mar 12 10:27:22 2009 -0700
@@ -34,17 +34,18 @@
  */
 
 class DeleteOnExitHook {
-    private static DeleteOnExitHook instance = null;
+    static {
+         sun.misc.SharedSecrets.getJavaLangAccess()
+             .registerShutdownHook(2 /* Shutdown hook invocation order */,
+                 new Runnable() {
+                     public void run() {
+                        runHooks();
+                     }
+                 });
+    }
 
     private static LinkedHashSet<String> files = new LinkedHashSet<String>();
 
-    static DeleteOnExitHook hook() {
-        if (instance == null)
-            instance = new DeleteOnExitHook();
-
-        return instance;
-    }
-
     private DeleteOnExitHook() {}
 
     static synchronized void add(String file) {
@@ -54,7 +55,7 @@
         files.add(file);
     }
 
-    void run() {
+    static void runHooks() {
         LinkedHashSet<String> theFiles;
 
         synchronized (DeleteOnExitHook.class) {