|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
util.CleanShutdown
public class CleanShutdown
A shutdown-hook that allows ExitCleaning and CancelRunnable
instances to be registered
to it. On shutdown, all registered ExitCleaning are brought into a
safe state by invoking their ExitCleaning.exit() method. All
CancelRunnable instances are canceled using their
CancelRunnable.cancel() method.
To provide at least some order, ExitCleaning and
CancelRunnable instances may be added
to this class using an additional priority parameter. Those
instances with a low priority are executed first. If no priority is given,
DEFPRIORITY is asumed.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
private static List<Object> |
avoid
A look-up list to avoid double-adding of ExitCleaning objects. |
private static TreeMap<Integer,List<Object>> |
clean
A map of ExitCleaning instances to be cleaned on shutdown. |
private static CleanShutdown |
CLEANSE
A shutdown-hook collecting necessary pre-exit jobs. |
static int |
DEFPRIORITY
The default priority. |
private static boolean |
HAVECLEANSED
True, if the CleanShutdown hook was added. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
private |
CleanShutdown()
Constructs a new shutdown-hook. |
| Method Summary | |
|---|---|
static void |
addShutdown(Object cleanup)
Adds an exit-cleaning instance to this shutdown hook using the default priority DEFPRIORITY. |
static void |
addShutdown(Object cleanup,
int priority)
Adds an exit-cleaning instance to this shutdown hook. |
void |
removeShutdown(Object remove)
Removes a previously registered ExitCleaning or
CancelRunnable instance from this
shutdown hook. |
void |
run()
Performs a ordered shutdown of all registered ExitCleaning and
CancelRunnable instances. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFPRIORITY
private static TreeMap<Integer,List<Object>> clean
ExitCleaning instances to be cleaned on shutdown.
private static List<Object> avoid
ExitCleaning objects.
private static CleanShutdown CLEANSE
private static boolean HAVECLEANSED
CleanShutdown hook was added.
| Constructor Detail |
|---|
private CleanShutdown()
ExitCleaning
instances may be registered and deregistered from the hook using
the addShutdown(java.lang.Object) and removeShutdown(java.lang.Object) methods.
| Method Detail |
|---|
public static void addShutdown(Object cleanup)
DEFPRIORITY.
public static void addShutdown(Object cleanup,
int priority)
ExitCleaning and CancelRunnable
instances. avoid is used to block
multiple insertion.
public void removeShutdown(Object remove)
ExitCleaning or
CancelRunnable instance from this
shutdown hook. If present in the avoid list, it is removed also
from the priority map by roaming through all values.
public void run()
ExitCleaning and
CancelRunnable instances. First, all
CancelRunnable.cancel() methods are invoked. Then, depending on
their priority, the rgistered objects are finalized in a way that for
ExitCleaning instances their ExitCleaning.exit() method
is invoked and CancelRunnable instances are joined to for
CancelRunnable.maxTimeToCancel(). Note that this clean-up is done
purely seqeuntial, which suggest that ExitCleaning instances
should be cleaned up fast and that CancelRunnable instances
should be finalized with low priority.CancelRunnable is
finalizing is done before the exit method.
run in interface Runnablerun in class Thread
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||