直接上代码
定时任务配置累,配置10个线程池
/**
* 定时任务县城池配置
* 可执行a,b任务并行,a,a任务串行
*/
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(Executors.newScheduledThreadPool(10));
}
}
测试代码
@Scheduled(cron = "${other.test1}")
private void test1() throws InterruptedException {
int a=1000;
for (int i=0 ;i<a;i++){
log.info("test1的:+ℹ️="+i);
Thread.sleep(1000L);
}
}
@Scheduled(cron = "${other.test2}")
private void test2() throws InterruptedException {
int a=1000;
for (int i=0 ;i<a;i++){
log.info("test2的:+ℹ️="+i);
Thread.sleep(1000L);
}
}
测试结果: