Class ShutdownHook
java.lang.Object
java.lang.Thread
clazzfish.core.util.ShutdownHook
- All Implemented Interfaces:
Shutdownable,Runnable
- Direct Known Subclasses:
AbstractMonitor,ClasspathAgent,ClazzStatistic
This class has the necessary methods for registration a class
as shutdown hook. For this you must overwrite the
Thread.run() method
which is called during shutdown.- Since:
- 3.0
- Author:
- oboehm
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidTo be able to register the class as shutdown hook via JMX we can't use a static method - this is the reason why this additional method was added.booleanHere you can ask if the class was already registered as shutdown hook.voidIf you want to unregister the instance as shutdown hook you can use this (not static) method.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, toString, yield
-
Constructor Details
-
ShutdownHook
public ShutdownHook()
-
-
Method Details
-
isShutdownHook
public boolean isShutdownHook()Here you can ask if the class was already registered as shutdown hook.- Specified by:
isShutdownHookin interfaceShutdownable- Returns:
- true if it is registered as shutdown hook.
-
addMeAsShutdownHook
public void addMeAsShutdownHook()To be able to register the class as shutdown hook via JMX we can't use a static method - this is the reason why this additional method was added.NOTE: Don't add a class as shutdown hook in a web environment, e.g. Tomcat or other servlet container. It may avoid Tomcat from shuttong down as expected.
- Specified by:
addMeAsShutdownHookin interfaceShutdownable
-
removeMeAsShutdownHook
public void removeMeAsShutdownHook()If you want to unregister the instance as shutdown hook you can use this (not static) method.- Specified by:
removeMeAsShutdownHookin interfaceShutdownable
-