接口 SmartLifecycle
- 所有已知子接口:
MessageListenerContainer
- 所有已知实现类:
AbstractBrokerMessageHandler
,AbstractJmsListeningContainer
,AbstractMessageListenerContainer
,AbstractPollingMessageListenerContainer
,AnnotatedEndpointConnectionManager
,ConnectionManagerSupport
,DefaultMessageListenerContainer
,EndpointConnectionManager
,GenericMessageEndpointManager
,JmsListenerEndpointRegistry
,JmsMessageEndpointManager
,SchedulerFactoryBean
,SimpAnnotationMethodMessageHandler
,SimpleBrokerMessageHandler
,SimpleMessageListenerContainer
,StompBrokerRelayMessageHandler
,SubProtocolWebSocketHandler
,UserDestinationMessageHandler
,WebSocketAnnotationMethodMessageHandler
,WebSocketConnectionManager
,WebSocketHandlerMapping
,WebSocketStompClient
public interface SmartLifecycle extends Lifecycle, Phased
An extension of theLifecycle
interface for those objects that require to be started upon ApplicationContext refresh and/or shutdown in a particular order. TheisAutoStartup()
return value indicates whether this object should be started at the time of a context refresh. The callback-acceptingstop(Runnable)
method is useful for objects that have an asynchronous shutdown process. Any implementation of this interface must invoke the callback'srun()
method upon shutdown completion to avoid unnecessary delays in the overall ApplicationContext shutdown.This interface extends
Phased
, and thePhased.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, andInteger.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 implementSmartLifecycle
will be treated as if they have a phase value of 0. That way aSmartLifecycle
implementation may start before thoseLifecycle
components if it has a negative phase value, or it may start after those components if it has a positive phase value.Note that, due to the auto-startup support in
SmartLifecycle
, aSmartLifecycle
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 onSmartLifecycle
beans.- 从以下版本开始:
- 3.0
- 作者:
- Mark Fisher
- 另请参阅:
LifecycleProcessor
,ConfigurableApplicationContext
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 boolean
isAutoStartup()
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.void
stop(Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.
方法详细资料
isAutoStartup
boolean isAutoStartup()
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.A value of
false
indicates that the component is intended to be started through an explicitLifecycle.start()
call instead, analogous to a plainLifecycle
implementation.
stop
void stop(Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessor
to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecycle
component does indeed stop.The
LifecycleProcessor
will call only this variant of thestop
method; i.e.Lifecycle.stop()
will not be called forSmartLifecycle
implementations unless explicitly delegated to within the implementation of this method.