@Slf4j @Configuration @EnableScheduling public class SchedulerConfig implements SchedulingConfigurer { @Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setScheduler(myTaskScheduler()); } @Bean public TaskScheduler myTaskScheduler() { // 允许同时执行多个定时任务 final int poolSize = 3; ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setPoolSize(poolSize); log.info(">> 配置定时任务线程池,允许同时执行{}个定时任务", poolSize); return taskScheduler; } }
使用定时任务
@Async @Scheduled(cron = "* * * * * ?") public void hello() throws InterruptedException { log.info("hello..."); Thread.sleep(3000); }
标签:info,taskScheduler,配置,poolSize,任务,定时,public From: https://www.cnblogs.com/jiutang001/p/16767256.html