Polishing
This commit is contained in:
@@ -41,6 +41,7 @@ import java.lang.annotation.Target;
|
||||
* <em>composed annotations</em> with attribute overrides.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @author Chris Beams
|
||||
* @since 3.0
|
||||
@@ -55,10 +56,10 @@ import java.lang.annotation.Target;
|
||||
public @interface Scheduled {
|
||||
|
||||
/**
|
||||
* A cron-like expression, extending the usual UN*X definition to include
|
||||
* triggers on the second as well as minute, hour, day of month, month
|
||||
* and day of week. e.g. {@code "0 * * * * MON-FRI"} means once per minute on
|
||||
* weekdays (at the top of the minute - the 0th second).
|
||||
* A cron-like expression, extending the usual UN*X definition to include triggers
|
||||
* on the second as well as minute, hour, day of month, month and day of week.
|
||||
* <p>E.g. {@code "0 * * * * MON-FRI"} means once per minute on weekdays
|
||||
* (at the top of the minute - the 0th second).
|
||||
* @return an expression that can be parsed to a cron schedule
|
||||
* @see org.springframework.scheduling.support.CronSequenceGenerator
|
||||
*/
|
||||
|
||||
@@ -105,7 +105,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
SmartInitializingSingleton, ApplicationListener<ContextRefreshedEvent>, DisposableBean {
|
||||
|
||||
/**
|
||||
* The default name of the {@link TaskScheduler} bean to pick up: "taskScheduler".
|
||||
* The default name of the {@link TaskScheduler} bean to pick up: {@value}.
|
||||
* <p>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
|
||||
@@ -231,12 +231,12 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
Assert.state(this.beanFactory != null, "BeanFactory must be set to find scheduler by type");
|
||||
try {
|
||||
// Search for TaskScheduler bean...
|
||||
this.registrar.setTaskScheduler(resolveSchedulerBean(beanFactory, TaskScheduler.class, false));
|
||||
this.registrar.setTaskScheduler(resolveSchedulerBean(this.beanFactory, TaskScheduler.class, false));
|
||||
}
|
||||
catch (NoUniqueBeanDefinitionException ex) {
|
||||
logger.debug("Could not find unique TaskScheduler bean", ex);
|
||||
try {
|
||||
this.registrar.setTaskScheduler(resolveSchedulerBean(beanFactory, TaskScheduler.class, true));
|
||||
this.registrar.setTaskScheduler(resolveSchedulerBean(this.beanFactory, TaskScheduler.class, true));
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex2) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
@@ -252,12 +252,12 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
logger.debug("Could not find default TaskScheduler bean", ex);
|
||||
// Search for ScheduledExecutorService bean next...
|
||||
try {
|
||||
this.registrar.setScheduler(resolveSchedulerBean(beanFactory, ScheduledExecutorService.class, false));
|
||||
this.registrar.setScheduler(resolveSchedulerBean(this.beanFactory, ScheduledExecutorService.class, false));
|
||||
}
|
||||
catch (NoUniqueBeanDefinitionException ex2) {
|
||||
logger.debug("Could not find unique ScheduledExecutorService bean", ex2);
|
||||
try {
|
||||
this.registrar.setScheduler(resolveSchedulerBean(beanFactory, ScheduledExecutorService.class, true));
|
||||
this.registrar.setScheduler(resolveSchedulerBean(this.beanFactory, ScheduledExecutorService.class, true));
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException ex3) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
@@ -340,6 +340,12 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the given {@code @Scheduled} method declaration on the given bean.
|
||||
* @param scheduled the @Scheduled annotation
|
||||
* @param method the method that the annotation has been declared on
|
||||
* @param bean the target bean instance
|
||||
*/
|
||||
protected void processScheduled(Scheduled scheduled, Method method, Object bean) {
|
||||
try {
|
||||
Assert.isTrue(method.getParameterCount() == 0,
|
||||
@@ -456,12 +462,8 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
|
||||
// Finally register the scheduled tasks
|
||||
synchronized (this.scheduledTasks) {
|
||||
Set<ScheduledTask> registeredTasks = this.scheduledTasks.get(bean);
|
||||
if (registeredTasks == null) {
|
||||
registeredTasks = new LinkedHashSet<>(4);
|
||||
this.scheduledTasks.put(bean, registeredTasks);
|
||||
}
|
||||
registeredTasks.addAll(tasks);
|
||||
Set<ScheduledTask> regTasks = this.scheduledTasks.computeIfAbsent(bean, key -> new LinkedHashSet<>(4));
|
||||
regTasks.addAll(tasks);
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
|
||||
Reference in New Issue
Block a user