--- a/jdk/src/share/classes/java/lang/ApplicationShutdownHooks.java Mon Mar 09 09:56:58 2009 -0400
+++ b/jdk/src/share/classes/java/lang/ApplicationShutdownHooks.java Thu Mar 12 10:27:22 2009 -0700
@@ -34,19 +34,19 @@
* @see java.lang.Runtime#removeShutdownHook
*/
-class ApplicationShutdownHooks implements Runnable {
- private static ApplicationShutdownHooks instance = null;
+class ApplicationShutdownHooks {
+ static {
+ Shutdown.add(1 /* shutdown hook invocation order */,
+ new Runnable() {
+ public void run() {
+ runHooks();
+ }
+ });
+ }
/* The set of registered hooks */
private static IdentityHashMap<Thread, Thread> hooks = new IdentityHashMap<Thread, Thread>();
- static synchronized ApplicationShutdownHooks hook() {
- if (instance == null)
- instance = new ApplicationShutdownHooks();
-
- return instance;
- }
-
private ApplicationShutdownHooks() {}
/* Add a new shutdown hook. Checks the shutdown state and the hook itself,
@@ -82,7 +82,7 @@
* to run in. Hooks are run concurrently and this method waits for
* them to finish.
*/
- public void run() {
+ static void runHooks() {
Collection<Thread> threads;
synchronized(ApplicationShutdownHooks.class) {
threads = hooks.keySet();