Class DefaultLifecycleProcessor
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,Lifecycle
,LifecycleProcessor
LifecycleProcessor
strategy.
Provides interaction with Lifecycle
and SmartLifecycle
beans in
groups for specific phases, on startup/shutdown as well as for explicit start/stop
interactions on a ConfigurableApplicationContext
.
As of 6.1, this also includes support for JVM checkpoint/restore (Project CRaC)
when the org.crac:crac
dependency on the classpath.
- Since:
- 3.0
- Author:
- Mark Fisher, Juergen Hoeller, Sebastien Deleuze
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Property name for a common context checkpoint: "spring.context.checkpoint".static final String
Property name for terminating the JVM when the context reaches a specific phase: "spring.context.exit".static final String
Recognized value for the context checkpoint and exit properties: "onRefresh". -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionRetrieve all applicable Lifecycle beans: all singletons that have already been created, as well as all SmartLifecycle beans (even if they are marked as lazy-init).protected int
Determine the lifecycle phase of the given bean.boolean
Check whether this component is currently running.void
onClose()
Notification of context close phase, for example, for auto-stopping components.void
Notification of context refresh, for example, for auto-starting components.void
setBeanFactory
(BeanFactory beanFactory) Callback that supplies the owning factory to a bean instance.void
setTimeoutForShutdownPhase
(int phase, long timeout) Specify the maximum time allotted for the shutdown of a specific phase (group ofSmartLifecycle
beans with the same 'phase' value).void
setTimeoutPerShutdownPhase
(long timeoutPerShutdownPhase) Specify the maximum time allotted in milliseconds for the shutdown of any phase (group ofSmartLifecycle
beans with the same 'phase' value).void
setTimeoutsForShutdownPhases
(Map<Integer, Long> timeoutsForShutdownPhases) Specify the maximum time allotted for the shutdown of each given phase (group ofSmartLifecycle
beans with the same 'phase' value).void
start()
Start all registered beans that implementLifecycle
and are not already running.void
stop()
Stop all registered beans that implementLifecycle
and are currently running.
-
Field Details
-
CHECKPOINT_PROPERTY_NAME
Property name for a common context checkpoint: "spring.context.checkpoint".- Since:
- 6.1
- See Also:
-
ON_REFRESH_VALUE
Core.checkpointRestore()
- Constant Field Values
-
EXIT_PROPERTY_NAME
Property name for terminating the JVM when the context reaches a specific phase: "spring.context.exit".- Since:
- 6.1
- See Also:
-
ON_REFRESH_VALUE
Recognized value for the context checkpoint and exit properties: "onRefresh".- Since:
- 6.1
- See Also:
-
-
Constructor Details
-
DefaultLifecycleProcessor
public DefaultLifecycleProcessor()
-
-
Method Details
-
setTimeoutsForShutdownPhases
Specify the maximum time allotted for the shutdown of each given phase (group ofSmartLifecycle
beans with the same 'phase' value).In case of no specific timeout configured, the default timeout per shutdown phase will apply: 10000 milliseconds (10 seconds) as of 6.2.
- Parameters:
timeoutsForShutdownPhases
- a map of phase values (matchingSmartLifecycle.getPhase()
) and corresponding timeout values (in milliseconds)- Since:
- 6.2
- See Also:
-
setTimeoutForShutdownPhase
public void setTimeoutForShutdownPhase(int phase, long timeout) Specify the maximum time allotted for the shutdown of a specific phase (group ofSmartLifecycle
beans with the same 'phase' value).In case of no specific timeout configured, the default timeout per shutdown phase will apply: 10000 milliseconds (10 seconds) as of 6.2.
- Parameters:
phase
- the phase value (matchingSmartLifecycle.getPhase()
)timeout
- the corresponding timeout value (in milliseconds)- Since:
- 6.2
- See Also:
-
setTimeoutPerShutdownPhase
public void setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase) Specify the maximum time allotted in milliseconds for the shutdown of any phase (group ofSmartLifecycle
beans with the same 'phase' value).The default value is 10000 milliseconds (10 seconds) as of 6.2.
- See Also:
-
setBeanFactory
Description copied from interface:BeanFactoryAware
Callback that supplies the owning factory to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Parameters:
beanFactory
- owning BeanFactory (nevernull
). The bean can immediately call methods on the factory.- See Also:
-
start
public void start()Start all registered beans that implementLifecycle
and are not already running. Any bean that implementsSmartLifecycle
will be started within its 'phase', and all phases will be ordered from lowest to highest value. All beans that do not implementSmartLifecycle
will be started in the default phase 0. A bean declared as a dependency of another bean will be started before the dependent bean regardless of the declared phase. -
stop
public void stop()Stop all registered beans that implementLifecycle
and are currently running. Any bean that implementsSmartLifecycle
will be stopped within its 'phase', and all phases will be ordered from highest to lowest value. All beans that do not implementSmartLifecycle
will be stopped in the default phase 0. A bean declared as dependent on another bean will be stopped before the dependency bean regardless of the declared phase. -
onRefresh
public void onRefresh()Description copied from interface:LifecycleProcessor
Notification of context refresh, for example, for auto-starting components.- Specified by:
onRefresh
in interfaceLifecycleProcessor
-
onClose
public void onClose()Description copied from interface:LifecycleProcessor
Notification of context close phase, for example, for auto-stopping components.- Specified by:
onClose
in interfaceLifecycleProcessor
-
isRunning
public boolean isRunning()Description copied from interface:Lifecycle
Check whether this component is currently running.In the case of a container, this will return
true
only if all components that apply are currently running. -
getLifecycleBeans
Retrieve all applicable Lifecycle beans: all singletons that have already been created, as well as all SmartLifecycle beans (even if they are marked as lazy-init).- Returns:
- the Map of applicable beans, with bean names as keys and bean instances as values
-
getPhase
Determine the lifecycle phase of the given bean.The default implementation checks for the
Phased
interface, using a default of 0 otherwise. Can be overridden to apply other/further policies.- Parameters:
bean
- the bean to introspect- Returns:
- the phase (an integer value)
- See Also:
-