public class DefaultShutdownCallbackRegistry extends Object implements ShutdownCallbackRegistry, LifeCycle2, Runnable
Runtime.addShutdownHook(Thread). If no strategy is specified,
this one is used for shutdown hook registration.LifeCycle.State| Modifier and Type | Field and Description |
|---|---|
protected static Logger |
LOGGER
Status logger.
|
SHUTDOWN_CALLBACK_REGISTRY, SHUTDOWN_HOOK_ENABLED, SHUTDOWN_HOOK_MARKER| Modifier | Constructor and Description |
|---|---|
|
DefaultShutdownCallbackRegistry()
Constructs a DefaultShutdownRegistrationStrategy.
|
protected |
DefaultShutdownCallbackRegistry(ThreadFactory threadFactory)
Constructs a DefaultShutdownRegistrationStrategy using the given
ThreadFactory. |
| Modifier and Type | Method and Description |
|---|---|
Cancellable |
addShutdownCallback(Runnable callback)
Adds a Runnable shutdown callback to this class.
|
LifeCycle.State |
getState()
Gets the life-cycle state.
|
void |
initialize() |
boolean |
isStarted()
Indicates if this can accept shutdown hooks.
|
boolean |
isStopped() |
void |
run()
Executes the registered shutdown callbacks.
|
void |
start()
Registers the shutdown thread only if this is initialized.
|
void |
stop() |
boolean |
stop(long timeout,
TimeUnit timeUnit)
Cancels the shutdown thread only if this is started.
|
protected static final Logger LOGGER
public DefaultShutdownCallbackRegistry()
protected DefaultShutdownCallbackRegistry(ThreadFactory threadFactory)
ThreadFactory.threadFactory - the ThreadFactory to use to create a Runtime shutdown hook threadpublic void run()
public Cancellable addShutdownCallback(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()
public boolean stop(long timeout,
TimeUnit timeUnit)
stop in interface LifeCycle2timeout - the maximum time to waittimeUnit - the time unit of the timeout argumentpublic LifeCycle.State getState()
LifeCyclepublic boolean isStarted()
Copyright © 1999-2021 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.