public class ShutDownHook extends Thread
callbacks to execute them in any order.
Example:
final ShutDownHook hook = new ShutDownHook();
hook.register(new Runnable() {
@Override
public void run() {
// Your shutdown code.
}
});
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
private Set<Callable<Void>> |
callbacks
Set of callbacks.
|
private static Logger |
DEFAULT_LOGGER
Default logger for this class.
|
private Logger |
logger
Logger instance.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
ShutDownHook()
Initializes
logger with DEFAULT_LOGGER. |
ShutDownHook(Logger logger)
Designated constructor.
|
| Modifier and Type | Method and Description |
|---|---|
ShutDownHook |
register(Callable<Void> callback)
Registers a callback.
|
ShutDownHook |
register(Runnable callback)
Registers a callback.
|
void |
run()
Iterates over all
callbacks and run them. |
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, yieldprivate static final Logger DEFAULT_LOGGER
private final Logger logger
public ShutDownHook()
logger with DEFAULT_LOGGER.public ShutDownHook(Logger logger)
logger - Logger to use by this class.public void run()
callbacks and run them.public ShutDownHook register(Runnable callback)
callback - must not be nullnull, self for chainingpublic ShutDownHook register(Callable<Void> callback)
callback - must not be nullnull, self for chainingCopyright © 2014 Sven Strittmatter. All Rights Reserved.