69 runFinalizersOnExit = run;
70 }
71 }
72
73
74 /**
75 * Add a new shutdown hook. Checks the shutdown state and the hook itself,
76 * but does not do any security checks.
77 *
78 * The registerShutdownInProgress parameter should be false except
79 * registering the DeleteOnExitHook since the first file may
80 * be added to the delete on exit list by the application shutdown
81 * hooks.
82 *
83 * @params slot the slot in the shutdown hook array, whose element
84 * will be invoked in order during shutdown
85 * @params registerShutdownInProgress true to allow the hook
86 * to be registered even if the shutdown is in progress.
87 * @params hook the hook to be registered
88 *
89 * @throw IllegalStateException
90 * if registerShutdownInProgress is false and shutdown is in progress; or
91 * if registerShutdownInProgress is true and the shutdown process
92 * already passes the given slot
93 */
94 static void add(int slot, boolean registerShutdownInProgress, Runnable hook) {
95 synchronized (lock) {
96 if (hooks[slot] != null)
97 throw new InternalError("Shutdown hook at slot " + slot + " already registered");
98
99 if (!registerShutdownInProgress) {
100 if (state > RUNNING)
101 throw new IllegalStateException("Shutdown in progress");
102 } else {
103 if (state > HOOKS || (state == HOOKS && slot <= currentRunningHook))
104 throw new IllegalStateException("Shutdown in progress");
105 }
106
107 hooks[slot] = hook;
108 }
109 }
|
69 runFinalizersOnExit = run;
70 }
71 }
72
73
74 /**
75 * Add a new shutdown hook. Checks the shutdown state and the hook itself,
76 * but does not do any security checks.
77 *
78 * The registerShutdownInProgress parameter should be false except
79 * registering the DeleteOnExitHook since the first file may
80 * be added to the delete on exit list by the application shutdown
81 * hooks.
82 *
83 * @params slot the slot in the shutdown hook array, whose element
84 * will be invoked in order during shutdown
85 * @params registerShutdownInProgress true to allow the hook
86 * to be registered even if the shutdown is in progress.
87 * @params hook the hook to be registered
88 *
89 * @throws IllegalStateException
90 * if registerShutdownInProgress is false and shutdown is in progress; or
91 * if registerShutdownInProgress is true and the shutdown process
92 * already passes the given slot
93 */
94 static void add(int slot, boolean registerShutdownInProgress, Runnable hook) {
95 synchronized (lock) {
96 if (hooks[slot] != null)
97 throw new InternalError("Shutdown hook at slot " + slot + " already registered");
98
99 if (!registerShutdownInProgress) {
100 if (state > RUNNING)
101 throw new IllegalStateException("Shutdown in progress");
102 } else {
103 if (state > HOOKS || (state == HOOKS && slot <= currentRunningHook))
104 throw new IllegalStateException("Shutdown in progress");
105 }
106
107 hooks[slot] = hook;
108 }
109 }
|