Package org.apache.commons.exec
Class ShutdownHookProcessDestroyer
java.lang.Object
org.apache.commons.exec.ShutdownHookProcessDestroyer
- All Implemented Interfaces:
Runnable
,ProcessDestroyer
Destroys all registered
Process
es when the VM exits.- Version:
- $Id: ShutdownHookProcessDestroyer.java 1636056 2014-11-01 21:12:52Z ggregory $
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs aProcessDestroyer
and obtainsRuntime.addShutdownHook()
andRuntime.removeShutdownHook()
through reflection. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if the specifiedProcess
was successfully added to the list of processes to destroy upon VM exit.boolean
Returns whether or not the ProcessDestroyer is registered as as shutdown hookboolean
Returnstrue
if the specifiedProcess
was successfully removed from the list of processes to destroy upon VM exit.void
run()
Invoked by the VM when it is exiting.int
size()
Returns the number of registered processes.
-
Constructor Details
-
ShutdownHookProcessDestroyer
public ShutdownHookProcessDestroyer()Constructs aProcessDestroyer
and 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, thisProcessDestroyer
is registered as a shutdown hook. If removing a process results in an empty list, theProcessDestroyer
is removed as a shutdown hook.
-
-
Method Details
-
isAddedAsShutdownHook
Returns whether or not the ProcessDestroyer is registered as as shutdown hook- Returns:
- true if this is currently added as shutdown hook
-
add
Returnstrue
if the specifiedProcess
was successfully added to the list of processes to destroy upon VM exit.- Specified by:
add
in interfaceProcessDestroyer
- Parameters:
process
- the process to add- Returns:
true
if the specifiedProcess
was successfully added
-
remove
Returnstrue
if the specifiedProcess
was successfully removed from the list of processes to destroy upon VM exit.- Specified by:
remove
in interfaceProcessDestroyer
- Parameters:
process
- the process to remove- Returns:
true
if the specifiedProcess
was successfully removed
-
size
Returns the number of registered processes.- Specified by:
size
in interfaceProcessDestroyer
- Returns:
- the number of register process
-
run
Invoked by the VM when it is exiting.
-