Using Spring's @Scheduled annotation with a specific executor
The Javadoc of @EnableScheduling
is pretty exhaustive in that area.
You need to implement a SchedulingConfigurer
to fine-tune which Executor
needs to be used.
@Configuration
@EnableScheduling
public class AppConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskScheduler());
}
@Bean
public Executor taskScheduler() {
ThreadPoolTaskScheduler t = new ThreadPoolTaskScheduler();
t.setPoolSize(2);
t.setThreadNamePrefix("taskScheduler - ");
t.initialize();
return t;
}
}
Executor qualification with @Scheduled is not supported yet.
Refer - https://jira.spring.io/browse/SPR-14218