< prev index next >

src/java.base/share/classes/java/lang/ApplicationShutdownHooks.java

Print this page
@@ -23,10 +23,11 @@
   * questions.
   */
  package java.lang;
  
  import java.util.*;
+ import java.util.concurrent.RejectedExecutionException;
  
  /*
   * Class to track and run user level shutdown hooks registered through
   * {@link Runtime#addShutdownHook Runtime.addShutdownHook}.
   *

@@ -95,13 +96,19 @@
          Collection<Thread> threads;
          synchronized(ApplicationShutdownHooks.class) {
              threads = hooks.keySet();
              hooks = null;
          }
- 
          for (Thread hook : threads) {
-             hook.start();
+             try {
+                 hook.start();
+             } catch (IllegalThreadStateException ignore) {
+                 // already started
+             } catch (RejectedExecutionException ignore) {
+                 // scheduler shutdown?
+                 assert hook.isVirtual();
+             }
          }
          for (Thread hook : threads) {
              while (true) {
                  try {
                      hook.join();
< prev index next >