Class DefaultShutdownCallbackRegistry
java.lang.Object
org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
- All Implemented Interfaces:
Runnable,LifeCycle,LifeCycle2,ShutdownCallbackRegistry
public class DefaultShutdownCallbackRegistry
extends Object
implements ShutdownCallbackRegistry, LifeCycle2, Runnable
ShutdownRegistrationStrategy that simply uses
Runtime.addShutdownHook(Thread). If no strategy is specified,
this one is used for shutdown hook registration.- Since:
- 2.1
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State -
Field Summary
FieldsFields inherited from interface org.apache.logging.log4j.core.util.ShutdownCallbackRegistry
SHUTDOWN_CALLBACK_REGISTRY, SHUTDOWN_HOOK_ENABLED, SHUTDOWN_HOOK_MARKER -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs a DefaultShutdownRegistrationStrategy.protectedDefaultShutdownCallbackRegistry(ThreadFactory threadFactory) Constructs a DefaultShutdownRegistrationStrategy using the givenThreadFactory. -
Method Summary
Modifier and TypeMethodDescriptionaddShutdownCallback(Runnable callback) Adds a Runnable shutdown callback to this class.getState()Gets the life-cycle state.voidbooleanIndicates if this can accept shutdown hooks.booleanvoidrun()Executes the registered shutdown callbacks.voidstart()Registers the shutdown thread only if this is initialized.voidstop()booleanCancels the shutdown thread only if this is started.
-
Field Details
-
LOGGER
Status logger.
-
-
Constructor Details
-
DefaultShutdownCallbackRegistry
public DefaultShutdownCallbackRegistry()Constructs a DefaultShutdownRegistrationStrategy. -
DefaultShutdownCallbackRegistry
Constructs a DefaultShutdownRegistrationStrategy using the givenThreadFactory.- Parameters:
threadFactory- the ThreadFactory to use to create aRuntimeshutdown hook thread
-
-
Method Details
-
run
public void run()Executes the registered shutdown callbacks. -
addShutdownCallback
Description copied from interface:ShutdownCallbackRegistryAdds a Runnable shutdown callback to this class. Note: The returnedCancellablemust be retained on heap by caller to avoid premature garbage-collection of the registered callback (and to ensure the callback runs on shutdown).- Specified by:
addShutdownCallbackin interfaceShutdownCallbackRegistry- Parameters:
callback- the shutdown callback to be executed upon shutdown.- Returns:
- a Cancellable wrapper of the provided callback or
nullif the shutdown hook is disabled and cannot be added.
-
initialize
public void initialize()- Specified by:
initializein interfaceLifeCycle
-
start
public void start()Registers the shutdown thread only if this is initialized. -
stop
public void stop() -
stop
Cancels the shutdown thread only if this is started.- Specified by:
stopin interfaceLifeCycle2- Parameters:
timeout- the maximum time to waittimeUnit- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
getState
Description copied from interface:LifeCycleGets the life-cycle state. -
isStarted
public boolean isStarted()Indicates if this can accept shutdown hooks. -
isStopped
public boolean isStopped()
-