用SpringBoot写的定时任务(共有100多个定时任务),发现CPU很高,开始还以为是SQL执行时间长,后面百度后才发现需要配置成多线程执行:
@Configuration public class XhsSchedulingConfigurer implements SchedulingConfigurer { @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setScheduler(Executors.newScheduledThreadPool(200)); } }
https://www.jianshu.com/p/602f1af3a4b1