< prev index next >

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

Print this page




  85             throw new NullPointerException();
  86 
  87         return hooks.remove(hook) != null;
  88     }
  89 
  90     /* Iterates over all application hooks creating a new thread for each
  91      * to run in. Hooks are run concurrently and this method waits for
  92      * them to finish.
  93      */
  94     static void runHooks() {
  95         Collection<Thread> threads;
  96         synchronized(ApplicationShutdownHooks.class) {
  97             threads = hooks.keySet();
  98             hooks = null;
  99         }
 100 
 101         for (Thread hook : threads) {
 102             hook.start();
 103         }
 104         for (Thread hook : threads) {

 105             try {
 106                 hook.join();
 107             } catch (InterruptedException x) { }



 108         }
 109     }
 110 }


  85             throw new NullPointerException();
  86 
  87         return hooks.remove(hook) != null;
  88     }
  89 
  90     /* Iterates over all application hooks creating a new thread for each
  91      * to run in. Hooks are run concurrently and this method waits for
  92      * them to finish.
  93      */
  94     static void runHooks() {
  95         Collection<Thread> threads;
  96         synchronized(ApplicationShutdownHooks.class) {
  97             threads = hooks.keySet();
  98             hooks = null;
  99         }
 100 
 101         for (Thread hook : threads) {
 102             hook.start();
 103         }
 104         for (Thread hook : threads) {
 105             while (true) {
 106                 try {
 107                     hook.join();
 108                     break;
 109                 } catch (InterruptedException ignored) {
 110                 }
 111             }
 112         }
 113     }
 114 }
< prev index next >