ThreadPoolTaskScheduler与ThreadPoolTaskExecutor区别
参考博客里面设置多个线程池,自己瞎玩中发现,我可以有多个ThreadPoolTaskExecutor的bean,但只能有一个ThreadPoolTaskScheduler的bean!
0.你看!!!!!它不让!!!!
java.lang.IllegalStateException: More than one TaskScheduler bean exists within the context, and none is named 'taskScheduler'. Mark one of them as primary or name it 'taskScheduler' (possibly as an alias); or implement the SchedulingConfigurer interface and call ScheduledTaskRegistrar#setScheduler explicitly within the configureTasks() callback.
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined: expected single matching bean but found 2: asyOneExecutor,asyThreeExecutor
1.实现类的不同
都继承了ExecutorConfigurationSupport
但实现有所区别
implements | ThreadPoolTaskExecutor | ThreadPoolTaskScheduler |
---|---|---|
AsyncListenableTaskExecutor | √ | √ |
SchedulingTaskExecutor | √ | √ |
TaskScheduler | × | √ |
So 问题应该出在TaskScheduler
据某博客说:
在springboot默认的线程池中,是单一线程。所以默认情况下,所有Scheduled不能并发执行。
意思是默认只能一个,能通过修改配置同时有多个调度器。(具体验证等我有空实施一下)
2.功能的不同
ThreadPoolTaskExecutor关注的是如何执行任务(how)
ThreadPoolTaskScheduler关注的是谁执行任务(who),何时去执行(when)
前者是可以设置线程池的核心参数的,如核心线程数,最大线程,等待队列等;后者不行,但后者能使用cron去设置触发时间
好了 我编不下去了,第一天就结束吧。。。等一个大佬来指导我。。。