Package org.apache.hadoop.util
Class ShutdownHookManager
java.lang.Object
org.apache.hadoop.util.ShutdownHookManager
The
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.
Unless a hook was registered with a shutdown explicitly set through
addShutdownHook(Runnable, int, long, TimeUnit),
the shutdown time allocated to it is set by the configuration option
CommonConfigurationKeysPublic.SERVICE_SHUTDOWN_TIMEOUT in
core-site.xml, with a default value of
CommonConfigurationKeysPublic.SERVICE_SHUTDOWN_TIMEOUT_DEFAULT
seconds.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TimeUnitThe default time unit used: seconds.static final longMinimum shutdown timeout: 1L second(s). -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShutdownHook(Runnable shutdownHook, int priority) Adds a shutdownHook with a priority, the higher the priority the earlier will run.voidaddShutdownHook(Runnable shutdownHook, int priority, long timeout, TimeUnit unit) Adds a shutdownHook with a priority and timeout the higher the priority the earlier will run.voidclear all registered shutdownHooks.static ShutdownHookManagerget()ReturnShutdownHookManagersingleton.booleanhasShutdownHook(Runnable shutdownHook) Indicates if a shutdownHook is registered or not.booleanIndicates if shutdown is in progress or not.booleanremoveShutdownHook(Runnable shutdownHook) Removes a shutdownHook.
-
Field Details
-
TIMEOUT_MINIMUM
public static final long TIMEOUT_MINIMUMMinimum shutdown timeout: 1L second(s).- See Also:
-
TIME_UNIT_DEFAULT
The default time unit used: seconds.
-
-
Method Details
-
get
ReturnShutdownHookManagersingleton.- Returns:
ShutdownHookManagersingleton.
-
addShutdownHook
Adds a shutdownHook with a priority, the higher the priority the earlier will run. ShutdownHooks with same priority run in a non-deterministic order.- Parameters:
shutdownHook- shutdownHookRunnablepriority- priority of the shutdownHook.
-
addShutdownHook
@Public @Stable public 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. ShutdownHooks with same priority run in a non-deterministic order. The shutdown hook will be terminated if it has not been finished in the specified period of time.- Parameters:
shutdownHook- shutdownHookRunnablepriority- priority of the shutdownHooktimeout- timeout of the shutdownHookunit- unit of the timeoutTimeUnit
-
removeShutdownHook
Removes a shutdownHook.- Parameters:
shutdownHook- shutdownHook to remove.- Returns:
- TRUE if the shutdownHook was registered and removed, FALSE otherwise.
-
hasShutdownHook
Indicates if a shutdownHook is registered or not.- Parameters:
shutdownHook- shutdownHook to check if registered.- Returns:
- TRUE/FALSE depending if the shutdownHook is is registered.
-
isShutdownInProgress
@Public @Stable public boolean isShutdownInProgress()Indicates if shutdown is in progress or not.- Returns:
- TRUE if the shutdown is in progress, otherwise FALSE.
-
clearShutdownHooks
@Public @Stable public void clearShutdownHooks()clear all registered shutdownHooks.
-