启动类加启动定时任务和启动异步的注解
@EnableAsync
@EnableScheduling
创建定时任务类
@Component
public class SimpleScheduleConfig {
@Scheduled(cron = "0 33 16 ? * THU")
@Async//开启异步方法
public void configureTasks1() throws InterruptedException {
//业务处理
System.err.println("A执行定时任务");
Thread.sleep(10000);
System.err.println("A执行定时任务: 休眠后");
}
@Scheduled(cron = "0 33 16 ? * THU")
@Async//开启异步方法
public void configureTasks2() throws InterruptedException {
//业务处理
System.err.println("B执行定时任务");
Thread.sleep(10000);
System.err.println("B执行定时任务: 休眠后");
}
}