FileDocCategorySizeDatePackage
ApplicationShutdownHooks.javaAPI DocJava SE 6 API2272Tue Jun 10 00:25:34 BST 2008java.lang

ApplicationShutdownHooks

public class ApplicationShutdownHooks extends Object implements Runnable

Fields Summary
private static ApplicationShutdownHooks
instance
private static IdentityHashMap
hooks
Constructors Summary
Methods Summary
private voidApplicationShutdownHooks()

static synchronized voidadd(java.lang.Thread hook)

	if(hooks == null)
	    throw new IllegalStateException("Shutdown in progress");

	if (hook.isAlive())
	    throw new IllegalArgumentException("Hook already running");

	if (hooks.containsKey(hook))
	    throw new IllegalArgumentException("Hook previously registered");

        hooks.put(hook, hook);
    
static synchronized java.lang.ApplicationShutdownHookshook()


        
	if (instance == null)
	    instance = new ApplicationShutdownHooks();

	return instance;
    
static synchronized booleanremove(java.lang.Thread hook)

	if(hooks == null)
	    throw new IllegalStateException("Shutdown in progress");

	if (hook == null) 
	    throw new NullPointerException();

	return hooks.remove(hook) != null;
    
public voidrun()

	Collection<Thread> threads;
	synchronized(ApplicationShutdownHooks.class) {
	    threads = hooks.keySet();
	    hooks = null;
	}

	for (Thread hook : threads) {
	    hook.start();
	}
	for (Thread hook : threads) {
	    try {
		hook.join();
	    } catch (InterruptedException x) { }
	}