@Component
@EnableScheduling //开启定时任务
//@EnableAsync //开启多线程(单线程执行可注释掉)
public class ScheduleTask {
@Async
@Scheduled(cron = "0 0 3 * * ?") //每天凌晨3点执行一次
public void saveTableInfoApiData() throws InterruptedException {
System.out.println("第一个定时任务开始:"+new Date()+"\r\n线程:"+Thread.currentThread().getName());
System.out.println("第一个定时任务执行完毕:");
}
@Async
@Scheduled(cron = "0 0 3 * * ?")
@PostConstruct //启动项目先执行一次
public void saveBloodData() throws InterruptedException {
System.out.println("第二个定时任务开始:"+new Date()+"\r\n线程:"+Thread.currentThread().getName());
System.out.println("第二个定时任务执行完毕:");
}
}
java基于spring的注解实现定时任务
最新推荐文章于 2023-11-16 16:44:39 发布