Class ScheduledAnnotationBeanPostProcessor
- All Implemented Interfaces:
EventListener, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor, ApplicationContextAware, ApplicationListener<ApplicationContextEvent>, EmbeddedValueResolverAware, org.springframework.core.Ordered, ScheduledTaskHolder
@Scheduled to be invoked by a
TaskScheduler according to the
"fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
This post-processor is automatically registered by Spring's
<task:annotation-driven> XML element and also by the
@EnableScheduling annotation.
Autodetects any SchedulingConfigurer instances in the container,
allowing for customization of the scheduler to be used or for fine-grained
control over task registration (for example, registration of Trigger tasks).
See the @EnableScheduling javadocs for complete usage
details.
- Since:
- 3.0
- Author:
- Mark Fisher, Juergen Hoeller, Chris Beams, Elizabeth Chatman, Victor Brown, Sam Brannen, Simon Baslé
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default name of theTaskSchedulerbean to pick up: "taskScheduler".protected final org.apache.commons.logging.LogFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a defaultScheduledAnnotationBeanPostProcessor.Create aScheduledAnnotationBeanPostProcessordelegating to the specifiedScheduledTaskRegistrar. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateRunnable(Object target, Method method) Deprecated.protected RunnablecreateRunnable(Object target, Method method, @Nullable String qualifier) Create aRunnablefor the given bean instance, calling the specified scheduled method.voiddestroy()intgetOrder()Return all currently scheduled tasks, fromScheduledmethods as well as from programmaticSchedulingConfigurerinteraction.voidReacts toContextRefreshedEventas well asContextClosedEvent: performingfinishRegistration()and early cancelling of scheduled tasks, respectively.postProcessAfterInitialization(Object bean, String beanName) voidpostProcessBeforeDestruction(Object bean, String beanName) postProcessBeforeInitialization(Object bean, String beanName) voidpostProcessMergedBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) protected voidprocessScheduled(Scheduled scheduled, Method method, Object bean) Process the given@Scheduledmethod declaration on the given bean, attempting to distinguish reactive methods from synchronous methods.booleanrequiresDestruction(Object bean) voidsetApplicationContext(ApplicationContext applicationContext) Setting anApplicationContextis optional: If set, registered tasks will be activated in theContextRefreshedEventphase; if not set, it will happen atafterSingletonsInstantiated()time.voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Making aBeanFactoryavailable is optional; if not set,SchedulingConfigurerbeans won't get autodetected and aschedulerhas to be explicitly configured.voidsetBeanName(String beanName) voidsetEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver) Set the StringValueResolver to use for resolving embedded definition values.voidsetScheduler(Object scheduler) Set theTaskSchedulerthat will invoke the scheduled methods, or aScheduledExecutorServiceto be wrapped as a TaskScheduler.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ApplicationListener
supportsAsyncExecutionMethods inherited from interface org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
resetBeanDefinition
-
Field Details
-
DEFAULT_TASK_SCHEDULER_BEAN_NAME
The default name of theTaskSchedulerbean to pick up: "taskScheduler".Note that the initial lookup happens by type; this is just the fallback in case of multiple scheduler beans found in the context.
- Since:
- 4.2
- See Also:
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
ScheduledAnnotationBeanPostProcessor
public ScheduledAnnotationBeanPostProcessor()Create a defaultScheduledAnnotationBeanPostProcessor. -
ScheduledAnnotationBeanPostProcessor
Create aScheduledAnnotationBeanPostProcessordelegating to the specifiedScheduledTaskRegistrar.- Parameters:
registrar- the ScheduledTaskRegistrar to register@Scheduledtasks on- Since:
- 5.1
-
-
Method Details
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
setScheduler
Set theTaskSchedulerthat will invoke the scheduled methods, or aScheduledExecutorServiceto be wrapped as a TaskScheduler.If not specified, default scheduler resolution will apply: searching for a unique
TaskSchedulerbean in the context, or for aTaskSchedulerbean named "taskScheduler" otherwise; the same lookup will also be performed for aScheduledExecutorServicebean. If neither of the two is resolvable, a local single-threaded default scheduler will be created within the registrar.- See Also:
-
setEmbeddedValueResolver
public void setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver) Description copied from interface:EmbeddedValueResolverAwareSet the StringValueResolver to use for resolving embedded definition values.- Specified by:
setEmbeddedValueResolverin interfaceEmbeddedValueResolverAware
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Making aBeanFactoryavailable is optional; if not set,SchedulingConfigurerbeans won't get autodetected and aschedulerhas to be explicitly configured.- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware
-
setApplicationContext
Setting anApplicationContextis optional: If set, registered tasks will be activated in theContextRefreshedEventphase; if not set, it will happen atafterSingletonsInstantiated()time.- Specified by:
setApplicationContextin interfaceApplicationContextAware- Parameters:
applicationContext- the ApplicationContext object to be used by this object- See Also:
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiatedin interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
postProcessMergedBeanDefinition
-
postProcessBeforeInitialization
-
postProcessAfterInitialization
-
processScheduled
Process the given@Scheduledmethod declaration on the given bean, attempting to distinguish reactive methods from synchronous methods.- Parameters:
scheduled- the@Scheduledannotationmethod- the method that the annotation has been declared onbean- the target bean instance- See Also:
-
createRunnable
Create aRunnablefor the given bean instance, calling the specified scheduled method.The default implementation creates a
ScheduledMethodRunnable.- Parameters:
target- the target bean instancemethod- the scheduled method to call- Since:
- 6.1
-
createRunnable
Deprecated.in favor ofcreateRunnable(Object, Method, String)Create aRunnablefor the given bean instance, calling the specified scheduled method.- Parameters:
target- the target bean instancemethod- the scheduled method to call- Since:
- 5.1
-
getScheduledTasks
Return all currently scheduled tasks, fromScheduledmethods as well as from programmaticSchedulingConfigurerinteraction.Note that this includes upcoming scheduled subscriptions for reactive methods but doesn't cover any currently active subscription for such methods.
- Specified by:
getScheduledTasksin interfaceScheduledTaskHolder- Since:
- 5.0.2
-
postProcessBeforeDestruction
-
requiresDestruction
- Specified by:
requiresDestructionin interfaceorg.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-
onApplicationEvent
Reacts toContextRefreshedEventas well asContextClosedEvent: performingfinishRegistration()and early cancelling of scheduled tasks, respectively.- Specified by:
onApplicationEventin interfaceApplicationListener<ApplicationContextEvent>- Parameters:
event- the event to respond to
-
createRunnable(Object, Method, String)