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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AtomicBoolean
Whether or not this ProcessDestroyer has been registered as a shutdown hook.The thread registered at the JVM to execute the shutdown handler.The list of currently running processes.private AtomicBoolean
Whether or not this ProcessDestroyer is currently running as shutdown hook. -
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.private void
Registers thisProcessDestroyer
as a shutdown hook.boolean
Tests whether or not the ProcessDestroyer is registered as shutdown hook.boolean
isEmpty()
Tests emptiness (size == 0).boolean
Returnstrue
if the specifiedProcess
was successfully removed from the list of processes to destroy upon VM exit.private void
Removes thisProcessDestroyer
as a shutdown hook.void
run()
Invoked by the VM when it is exiting.int
size()
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
Whether or not this ProcessDestroyer has been registered as a shutdown hook. -
running
Whether or not this ProcessDestroyer is currently running as shutdown hook.
-
-
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
-
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.
-
addShutdownHook
private void addShutdownHook()Registers thisProcessDestroyer
as a shutdown hook. -
isAddedAsShutdownHook
public boolean isAddedAsShutdownHook()Tests whether or not the ProcessDestroyer is registered as shutdown hook.- Returns:
- true if this is currently added as shutdown hook.
-
isEmpty
public boolean isEmpty()Tests emptiness (size == 0).- Returns:
- Whether or not this is empty.
- Since:
- 1.4.0
-
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.
-
removeShutdownHook
private void removeShutdownHook()Removes thisProcessDestroyer
as a shutdown hook. -
run
public void run()Invoked by the VM when it is exiting. -
size
public int size()Returns the number of registered processes.- Specified by:
size
in interfaceProcessDestroyer
- Returns:
- the number of register process.
-