Affects: \5.3.3
I find a strange thing that schedule job is synchronous execute And hava to config this as below to execute asynchronous:
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {
// ==== size for thread
private final int POOL_SIZE = 10;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
threadPoolTaskScheduler.setThreadNamePrefix("scheduled-task-pool-");
threadPoolTaskScheduler.initialize();
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
}
}
============================================================== And synchronous schedule result in that ,eg.I have 2 job to execute in 11:00,one of jobs cost 30min because of businsess,so other job has to waite ,that is unreasonable? eg:
@Scheduled(cron = "0 0 11 * * ?")
public void test01() throws InterruptedException {
System.out.println("test01 beging......");
TimeUnit.MINUTES.sleep(30);
System.out.println("test01 end......");
}
@Scheduled(cron = "0 0 11 * * ?")
public void test02() throws InterruptedException {
System.out.println("test02 beging......");
TimeUnit.SECONDS.sleep(3);
System.out.println("test02 end......");
}
At second,spring own async function for taskThread,So why not set Schedule Thread?
Looking forward to your reply。
Comment From: snicoll
The Javadoc of @EnableScheduling
states that:
By default, Spring will search for an associated scheduler definition: either a unique org.springframework.scheduling.TaskScheduler bean in the context, or a TaskScheduler bean named "taskScheduler" otherwise; the same lookup will also be performed for a java.util.concurrent.ScheduledExecutorService bean. If neither of the two is resolvable, a local single-threaded default scheduler will be created and used within the registrar.
Without a configuration on your end, the default is single threaded so I suspect that's what you mean by synchronous. I don't thiks there's anything else we can do here. Going forward, please ask questions on StackOverflow, as mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements.