Interface SmartLifecycle
- All Known Subinterfaces:
- MessageListenerContainer
- All Known Implementing Classes:
- AbstractBrokerMessageHandler,- AbstractJmsListeningContainer,- AbstractMessageListenerContainer,- AbstractPollingMessageListenerContainer,- AnnotatedEndpointConnectionManager,- ConnectionManagerSupport,- DefaultMessageListenerContainer,- EndpointConnectionManager,- ExecutorConfigurationSupport,- GenericMessageEndpointManager,- JmsListenerEndpointRegistry,- JmsMessageEndpointManager,- ReactorClientHttpConnector,- ReactorNettyClientRequestFactory,- ScheduledExecutorFactoryBean,- SchedulerFactoryBean,- SimpAnnotationMethodMessageHandler,- SimpleAsyncTaskScheduler,- SimpleBrokerMessageHandler,- SimpleMessageListenerContainer,- StompBrokerRelayMessageHandler,- SubProtocolWebSocketHandler,- ThreadPoolExecutorFactoryBean,- ThreadPoolTaskExecutor,- ThreadPoolTaskScheduler,- UserDestinationMessageHandler,- WebSocketAnnotationMethodMessageHandler,- WebSocketConnectionManager,- WebSocketHandlerMapping,- WebSocketStompClient
Lifecycle interface for those objects that require
 to be started upon ApplicationContext refresh and/or shutdown in a
 particular order.
 The isAutoStartup() return value indicates whether this object should
 be started at the time of a context refresh. The callback-accepting
 stop(Runnable) method is useful for objects that have an asynchronous
 shutdown process. Any implementation of this interface must invoke the
 callback's run() method upon shutdown completion to avoid unnecessary
 delays in the overall ApplicationContext shutdown.
 
This interface extends Phased, and the getPhase() method's
 return value indicates the phase within which this Lifecycle component
 should be started and stopped. The startup process begins with the lowest
 phase value and ends with the highest phase value (Integer.MIN_VALUE
 is the lowest possible, and Integer.MAX_VALUE is the highest possible).
 The shutdown process will apply the reverse order. Any components with the
 same value will be arbitrarily ordered within the same phase.
 
Example: if component B depends on component A having already started, then component A should have a lower phase value than component B. During the shutdown process, component B would be stopped before component A.
Any explicit "depends-on" relationship will take precedence over the phase order such that the dependent bean always starts after its dependency and always stops before its dependency.
Any Lifecycle components within the context that do not also
 implement SmartLifecycle will be treated as if they have a phase
 value of 0. This allows a SmartLifecycle component to start
 before those Lifecycle components if the SmartLifecycle
 component has a negative phase value, or the SmartLifecycle component
 may start after those Lifecycle components if the SmartLifecycle
 component has a positive phase value.
 
Note that, due to the auto-startup support in SmartLifecycle, a
 SmartLifecycle bean instance will usually get initialized on startup
 of the application context in any case. As a consequence, the bean definition
 lazy-init flag has very limited actual effect on SmartLifecycle beans.
- Since:
- 3.0
- Author:
- Mark Fisher, Juergen Hoeller, Sam Brannen
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intThe default phase forSmartLifecycle:Integer.MAX_VALUE.
- 
Method SummaryModifier and TypeMethodDescriptiondefault intgetPhase()Return the phase that this lifecycle object is supposed to run in.default booleanReturnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.default voidIndicates that a Lifecycle component must stop if it is currently running.
- 
Field Details- 
DEFAULT_PHASEstatic final int DEFAULT_PHASEThe default phase forSmartLifecycle:Integer.MAX_VALUE.This is different from the common phase 0associated with regularLifecycleimplementations, putting the typically auto-startedSmartLifecyclebeans into a later startup phase and an earlier shutdown phase.Note that certain SmartLifecyclecomponents come with a different default phase: e.g. executors/schedulers withInteger.MAX_VALUE / 2.
 
- 
- 
Method Details- 
isAutoStartupdefault boolean isAutoStartup()Returnstrueif thisLifecyclecomponent should get started automatically by the container at the time that the containingApplicationContextgets refreshed.A value of falseindicates that the component is intended to be started through an explicitLifecycle.start()call instead, analogous to a plainLifecycleimplementation.The default implementation returns true.
- 
stopIndicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the LifecycleProcessorto support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecyclecomponent does indeed stop.The LifecycleProcessorwill call only this variant of thestopmethod; i.e.Lifecycle.stop()will not be called forSmartLifecycleimplementations unless explicitly delegated to within the implementation of this method.The default implementation delegates to Lifecycle.stop()and immediately triggers the given callback in the calling thread. Note that there is no synchronization between the two, so custom implementations may at least want to put the same steps within their common lifecycle monitor (if any).- See Also:
 
- 
getPhasedefault int getPhase()Return the phase that this lifecycle object is supposed to run in.The default implementation returns DEFAULT_PHASEin order to letstop()callbacks execute before regularLifecycleimplementations.
 
-