@Public
@Evolving
public final class ShutdownHookManager
extends java.lang.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.
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.
| Modifier and Type | Field | Description |
|---|---|---|
static java.util.concurrent.TimeUnit |
TIME_UNIT_DEFAULT |
The default time unit used: seconds.
|
static long |
TIMEOUT_MINIMUM |
Minimum shutdown timeout: 1L second(s).
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addShutdownHook(java.lang.Runnable shutdownHook,
int priority) |
Adds a shutdownHook with a priority, the higher the priority
the earlier will run.
|
void |
addShutdownHook(java.lang.Runnable shutdownHook,
int priority,
long timeout,
java.util.concurrent.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(java.lang.Runnable shutdownHook) |
Indicates if a shutdownHook is registered or not.
|
boolean |
isShutdownInProgress() |
Indicates if shutdown is in progress or not.
|
boolean |
removeShutdownHook(java.lang.Runnable shutdownHook) |
Removes a shutdownHook.
|
public static final long TIMEOUT_MINIMUM
public static final java.util.concurrent.TimeUnit TIME_UNIT_DEFAULT
@Public public static ShutdownHookManager get()
ShutdownHookManager singleton.ShutdownHookManager singleton.@Public
@Stable
public void addShutdownHook(java.lang.Runnable shutdownHook,
int priority)
shutdownHook - shutdownHook Runnablepriority - priority of the shutdownHook.@Public
@Stable
public void addShutdownHook(java.lang.Runnable shutdownHook,
int priority,
long timeout,
java.util.concurrent.TimeUnit unit)
shutdownHook - shutdownHook Runnablepriority - priority of the shutdownHooktimeout - timeout of the shutdownHookunit - unit of the timeout TimeUnit@Public @Stable public boolean removeShutdownHook(java.lang.Runnable shutdownHook)
shutdownHook - shutdownHook to remove.@Public @Stable public boolean hasShutdownHook(java.lang.Runnable shutdownHook)
shutdownHook - shutdownHook to check if registered.@Public @Stable public boolean isShutdownInProgress()
@Public @Stable public void clearShutdownHooks()
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.