Package org.zeroturnaround.exec.listener
Class ShutdownHookProcessDestroyer
java.lang.Object
org.zeroturnaround.exec.listener.ShutdownHookProcessDestroyer
- All Implemented Interfaces:
Runnable
,ProcessDestroyer
Destroys all registered
Process
es when the VM exits.
This class is copied from Commons Exec
.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Whether or not this ProcessDestroyer has been registered as a shutdown hookThe thread registered at the JVM to execute the shutdown handlerstatic final ProcessDestroyer
Singleton instance of theShutdownHookProcessDestroyer
.private static final org.slf4j.Logger
the list of currently running processesprivate boolean
Whether or not this ProcessDestroyer is currently running as shutdown hookprivate boolean
Whether the shut down hook routine was already run -
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, uses reflection to ensure pre-JDK 1.3 compatibility.private void
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.private void
Removes thisProcessDestroyer
as a shutdown hook, uses reflection to ensure pre-JDK 1.3 compatibilityvoid
run()
Invoked by the VM when it is exiting.int
size()
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 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
-
addShutdownHook
private void addShutdownHook()Registers thisProcessDestroyer
as a shutdown hook, uses reflection to ensure pre-JDK 1.3 compatibility. -
removeShutdownHook
private void removeShutdownHook()Removes thisProcessDestroyer
as 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
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
public int size()Returns the number of registered processes.- Specified by:
size
in interfaceProcessDestroyer
- Returns:
- the number of register process
-
run
public void run()Invoked by the VM when it is exiting. -
destroy
-