public class DefaultShutdownCallbackRegistry extends java.lang.Object implements ShutdownCallbackRegistry, LifeCycle2, java.lang.Runnable
Runtime.addShutdownHook(Thread). If no strategy is specified,
this one is used for shutdown hook registration.| Modifier and Type | Class and Description |
|---|---|
private static class |
DefaultShutdownCallbackRegistry.RegisteredCancellable |
LifeCycle.State| Modifier and Type | Field and Description |
|---|---|
private java.util.Collection<Cancellable> |
hooks |
protected static Logger |
LOGGER
Status logger.
|
private java.lang.ref.Reference<java.lang.Thread> |
shutdownHookRef |
private java.util.concurrent.atomic.AtomicReference<LifeCycle.State> |
state |
private java.util.concurrent.ThreadFactory |
threadFactory |
SHUTDOWN_CALLBACK_REGISTRY, SHUTDOWN_HOOK_ENABLED, SHUTDOWN_HOOK_MARKER| Modifier | Constructor and Description |
|---|---|
|
DefaultShutdownCallbackRegistry()
Constructs a DefaultShutdownRegistrationStrategy.
|
protected |
DefaultShutdownCallbackRegistry(java.util.concurrent.ThreadFactory threadFactory)
Constructs a DefaultShutdownRegistrationStrategy using the given
ThreadFactory. |
| Modifier and Type | Method and Description |
|---|---|
Cancellable |
addShutdownCallback(java.lang.Runnable callback)
Adds a Runnable shutdown callback to this class.
|
private void |
addShutdownHook(java.lang.Thread thread) |
LifeCycle.State |
getState()
Gets the life-cycle state.
|
void |
initialize() |
boolean |
isStarted()
Indicates if this can accept shutdown hooks.
|
boolean |
isStopped() |
private void |
removeShutdownHook() |
void |
run()
Executes the registered shutdown callbacks.
|
void |
start()
Registers the shutdown thread only if this is initialized.
|
void |
stop() |
boolean |
stop(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Cancels the shutdown thread only if this is started.
|
protected static final Logger LOGGER
private final java.util.concurrent.atomic.AtomicReference<LifeCycle.State> state
private final java.util.concurrent.ThreadFactory threadFactory
private final java.util.Collection<Cancellable> hooks
private java.lang.ref.Reference<java.lang.Thread> shutdownHookRef
public DefaultShutdownCallbackRegistry()
protected DefaultShutdownCallbackRegistry(java.util.concurrent.ThreadFactory threadFactory)
ThreadFactory.threadFactory - the ThreadFactory to use to create a Runtime shutdown hook threadpublic void run()
run in interface java.lang.Runnablepublic Cancellable addShutdownCallback(java.lang.Runnable callback)
ShutdownCallbackRegistryaddShutdownCallback in interface ShutdownCallbackRegistrycallback - the shutdown callback to be executed upon shutdown.null if the shutdown hook is disabled and
cannot be added.public void initialize()
initialize in interface LifeCyclepublic void start()
private void addShutdownHook(java.lang.Thread thread)
public boolean stop(long timeout,
java.util.concurrent.TimeUnit timeUnit)
stop in interface LifeCycle2timeout - the maximum time to waittimeUnit - the time unit of the timeout argumentprivate void removeShutdownHook()
public LifeCycle.State getState()
LifeCyclepublic boolean isStarted()