更新时间:2023-09-19 14:32:10
我猜测你并没有指定定时任务的pool size,所以默认所有schedule的共用一个线程。需要指定schedule 的pool size大小
xml
<task :annotation-driven scheduler ="myScheduler" />
<task :scheduler id ="myScheduler" pool-size ="10" />
bean
@Bean(destroyMethod = "shutdown")
public Executor taskScheduler() {
return Executors.newScheduledThreadPool(10);
}
补充:
共用一个线程将带来严重的问题。如果A任务没有在2小时内执行完,那么B任务的执行时间将延后,甚至不执行。