public class ShutdownThread extends Thread
Provides a standard way of notifying when an application is shutting down.
Functions can be specified as ShutdownFunctions to be run serially as the application shuts down
Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
private String |
applicationName |
private static org.slf4j.Logger |
log |
private List<ShutdownFunction> |
shutdownFunctions |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
ShutdownThread(String applicationName) |
ShutdownThread(String applicationName,
List<ShutdownFunction> shutdownFunctions) |
| Modifier and Type | Method and Description |
|---|---|
ShutdownThread |
addShutdownFunction(ShutdownFunction function) |
static void |
addShutdownListener(ShutdownThread thread)
Adds the specified shutdown listener to be executed when the JVM signals its going to halt
|
void |
run() |
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 org.slf4j.Logger log
private final String applicationName
private final List<ShutdownFunction> shutdownFunctions
public ShutdownThread(String applicationName)
public ShutdownThread(String applicationName, List<ShutdownFunction> shutdownFunctions) throws IllegalArgumentException
applicationName - The name of the application for loggingshutdownFunctions - The list of functions that should be executed when the JVM signals
it is exiting. This cannot be null.IllegalArgumentException - If either parameter is nullpublic ShutdownThread addShutdownFunction(ShutdownFunction function) throws IllegalArgumentException, IllegalStateException
IllegalArgumentException - If the function to add is nullIllegalStateException - If the thread is running when the add takes placepublic static void addShutdownListener(ShutdownThread thread)
Copyright © 2017. All rights reserved.