最近收到了很多封邮件,都是想知道spring boot整合quartz如何实现多个定时任务的,由于本人生产上并没有使用到多个定时任务,这里给个实现的思路。
1、新建两个定时任务,如下:
public class ScheduledJob implements Job{
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("schedule job1 is running…………………………………… ");
}
}
public class ScheduledJob2 implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("schedule job2 is running ……………………………………………………");
}
}
2、配置以上两个任务
@Component
public class SchedulerAllJob {
@Autowired
private SchedulerFactoryBean schedulerFactoryBean;
/*
* 此处可以注入数据库操作,查询出所有的任务配置
*/
/**
* 该