Package org.zeroturnaround.exec.listener
Class ShutdownHookProcessDestroyer
java.lang.Object
org.zeroturnaround.exec.listener.ShutdownHookProcessDestroyer
- All Implemented Interfaces:
Runnable,ProcessDestroyer
Destroys all registered
Processes when the VM exits.
This class is copied from Commons Exec.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether or not this ProcessDestroyer has been registered as a shutdown hookThe thread registered at the JVM to execute the shutdown handlerstatic final ProcessDestroyerSingleton instance of theShutdownHookProcessDestroyer.private static final org.slf4j.Loggerthe list of currently running processesprivate booleanWhether or not this ProcessDestroyer is currently running as shutdown hookprivate booleanWhether the shut down hook routine was already run -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aProcessDestroyerand obtainsRuntime.addShutdownHook()andRuntime.removeShutdownHook()through reflection. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif the specifiedProcesswas successfully added to the list of processes to destroy upon VM exit.private voidRegisters thisProcessDestroyeras a shutdown hook, uses reflection to ensure pre-JDK 1.3 compatibility.private voidbooleanReturns whether or not the ProcessDestroyer is registered as as shutdown hookbooleanReturnstrueif the specifiedProcesswas successfully removed from the list of processes to destroy upon VM exit.private voidRemoves thisProcessDestroyeras a shutdown hook, uses reflection to ensure pre-JDK 1.3 compatibilityvoidrun()Invoked by the VM when it is exiting.intsize()Returns the number of registered processes.
-
Field Details
-
log
private static final org.slf4j.Logger log -
INSTANCE
Singleton instance of theShutdownHookProcessDestroyer. -
processes
the list of currently running processes -
destroyProcessThread
The thread registered at the JVM to execute the shutdown handler -
added
private boolean addedWhether or not this ProcessDestroyer has been registered as a shutdown hook -
shutDownHookExecuted
private volatile boolean shutDownHookExecutedWhether the shut down hook routine was already run -
running
private volatile boolean runningWhether or not this ProcessDestroyer is currently running as shutdown hook
-
-
Constructor Details
-
ShutdownHookProcessDestroyer
public ShutdownHookProcessDestroyer()Constructs aProcessDestroyerand obtainsRuntime.addShutdownHook()andRuntime.removeShutdownHook()through reflection. The ProcessDestroyer manages a list of processes to be destroyed when the VM exits. If a process is added when the list is empty, thisProcessDestroyeris registered as a shutdown hook. If removing a process results in an empty list, theProcessDestroyeris removed as a shutdown hook.
-
-
Method Details
-
addShutdownHook
private void addShutdownHook()Registers thisProcessDestroyeras a shutdown hook, uses reflection to ensure pre-JDK 1.3 compatibility. -
removeShutdownHook
private void removeShutdownHook()Removes thisProcessDestroyeras a shutdown hook, uses reflection to ensure pre-JDK 1.3 compatibility -
isAddedAsShutdownHook
public boolean isAddedAsShutdownHook()Returns whether or not the ProcessDestroyer is registered as as shutdown hook- Returns:
- true if this is currently added as shutdown hook
-
add
Returnstrueif the specifiedProcesswas successfully added to the list of processes to destroy upon VM exit.- Specified by:
addin interfaceProcessDestroyer- Parameters:
process- the process to add- Returns:
trueif the specifiedProcesswas successfully added
-
remove
Returnstrueif the specifiedProcesswas successfully removed from the list of processes to destroy upon VM exit.- Specified by:
removein interfaceProcessDestroyer- Parameters:
process- the process to remove- Returns:
trueif the specifiedProcesswas successfully removed
-
size
public int size()Returns the number of registered processes.- Specified by:
sizein interfaceProcessDestroyer- Returns:
- the number of register process
-
run
public void run()Invoked by the VM when it is exiting. -
destroy
-