jdk/src/share/classes/java/lang/ApplicationShutdownHooks.java
changeset 2703 acd4d6a53e3e
parent 2277 445a331b4a8b
child 5506 202f599c92aa
--- a/jdk/src/share/classes/java/lang/ApplicationShutdownHooks.java	Thu Apr 23 19:44:43 2009 +0100
+++ b/jdk/src/share/classes/java/lang/ApplicationShutdownHooks.java	Mon Apr 27 12:08:41 2009 -0700
@@ -35,17 +35,26 @@
  */
 
 class ApplicationShutdownHooks {
+    /* The set of registered hooks */
+    private static IdentityHashMap<Thread, Thread> hooks;
     static {
-        Shutdown.add(1 /* shutdown hook invocation order */,
-            new Runnable() {
-                public void run() {
-                    runHooks();
+        try {
+            Shutdown.add(1 /* shutdown hook invocation order */,
+                false /* not registered if shutdown in progress */,
+                new Runnable() {
+                    public void run() {
+                        runHooks();
+                    }
                 }
-            });
+            );
+            hooks = new IdentityHashMap<Thread, Thread>();
+        } catch (IllegalStateException e) {
+            // application shutdown hooks cannot be added if
+            // shutdown is in progress.
+            hooks = null;
+        }
     }
 
-    /* The set of registered hooks */
-    private static IdentityHashMap<Thread, Thread> hooks = new IdentityHashMap<Thread, Thread>();
 
     private ApplicationShutdownHooks() {}