接口 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 uponApplicationContext
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-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 overallApplicationContext
shutdown.This interface extends
Phased
, and thegetPhase()
method's return value indicates the phase within which thisLifecycle
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 of0
. This allows aSmartLifecycle
component to start before thoseLifecycle
components if theSmartLifecycle
component has a negative phase value, or theSmartLifecycle
component may start after thoseLifecycle
components if theSmartLifecycle
component 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, Juergen Hoeller, Sam Brannen
- 另请参阅:
LifecycleProcessor
,ConfigurableApplicationContext
字段概要
字段 修饰符和类型 字段 说明 static int
DEFAULT_PHASE
The default phase forSmartLifecycle
:Integer.MAX_VALUE
.
方法概要
所有方法 实例方法 默认方法 修饰符和类型 方法 说明 default int
getPhase()
Return the phase that this lifecycle object is supposed to run in.default boolean
isAutoStartup()
Returnstrue
if thisLifecycle
component should get started automatically by the container at the time that the containingApplicationContext
gets refreshed.default void
stop(Runnable callback)
Indicates that a Lifecycle component must stop if it is currently running.
字段详细资料
DEFAULT_PHASE
static final int DEFAULT_PHASE
The default phase forSmartLifecycle
:Integer.MAX_VALUE
.This is different from the common phase
0
associated with regularLifecycle
implementations, putting the typically auto-startedSmartLifecycle
beans into a later startup phase and an earlier shutdown phase.- 从以下版本开始:
- 5.1
- 另请参阅:
getPhase()
,DefaultLifecycleProcessor.getPhase(Lifecycle)
, 常量字段值
方法详细资料
isAutoStartup
default 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.The default implementation returns
true
.
stop
default 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.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).- 另请参阅:
Lifecycle.stop()
,getPhase()
getPhase
default int getPhase()
Return the phase that this lifecycle object is supposed to run in.The default implementation returns
DEFAULT_PHASE
in order to letstop()
callbacks execute after regularLifecycle
implementations.