Package org.apache.commons.exec
Class ShutdownHookProcessDestroyer
java.lang.Object
org.apache.commons.exec.ShutdownHookProcessDestroyer
- All Implemented Interfaces:
Runnable,ProcessDestroyer
Destroys all registered
Processes when the VM exits.- Version:
- $Id: ShutdownHookProcessDestroyer.java 1636056 2014-11-01 21:12:52Z ggregory $
-
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 handlerthe list of currently running processesprivate booleanWhether or not this ProcessDestroyer is currently running as shutdown hook -
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.booleanReturns 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
-
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 -
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.
-