public class ShutdownHookManager extends Object
ShutdownHookManager
enables running shutdownHook
in a deterministic order, higher priority first.
The JVM runs ShutdownHooks in a non-deterministic order or in parallel.
This class registers a single JVM shutdownHook and run all the
shutdownHooks registered to it (to this class) in order based on their
priority.Modifier and Type | Method and Description |
---|---|
void |
addShutdownHook(Runnable shutdownHook,
int priority)
Adds a shutdownHook with a priority, the higher the priority
the earlier will run.
|
void |
addShutdownHook(Runnable shutdownHook,
int priority,
long timeout,
TimeUnit unit)
Adds a shutdownHook with a priority and timeout the higher the priority
the earlier will run.
|
void |
clearShutdownHooks()
clear all registered shutdownHooks.
|
static ShutdownHookManager |
get()
Return
ShutdownHookManager singleton. |
boolean |
hasShutdownHook(Runnable shutdownHook)
Indicates if a shutdownHook is registered or not.
|
boolean |
isShutdownInProgress()
Indicates if shutdown is in progress or not.
|
boolean |
removeShutdownHook(Runnable shutdownHook)
Removes a shutdownHook.
|
public static ShutdownHookManager get()
ShutdownHookManager
singleton.ShutdownHookManager
singleton.public void addShutdownHook(Runnable shutdownHook, int priority)
shutdownHook
- shutdownHook Runnable
priority
- priority of the shutdownHook.public void addShutdownHook(Runnable shutdownHook, int priority, long timeout, TimeUnit unit)
shutdownHook
- shutdownHook Runnable
priority
- priority of the shutdownHooktimeout
- timeout of the shutdownHookunit
- unit of the timeout TimeUnit
public boolean removeShutdownHook(Runnable shutdownHook)
shutdownHook
- shutdownHook to remove.public boolean hasShutdownHook(Runnable shutdownHook)
shutdownHook
- shutdownHook to check if registered.public boolean isShutdownInProgress()
public void clearShutdownHooks()
Copyright © 2017 Apache Software Foundation. All Rights Reserved.