Quartz 配置文件,如果是基于maven 的项目只需要放置到src/main/resources目录下
#quartz setting File
# quartz instance Name
org.quartz .scheduler .instanceName = MySchedulerVincent
# quarts thread pool size =3 ; maximum of 3 jobs can be run simultaneously.
org.quartz .threadPool .threadCount = 3
# All of Quartz’s data, such as details of jobs and triggers, is held in memory
org.quartz .jobStore .class = org.quartz .simpl .RAMJobStore
quartz Pom配置
<dependency >
<groupId > org.quartz-scheduler</groupId >
<artifactId > quartz</artifactId >
<version > 2.2.1</version >
</dependency >
<dependency >
<groupId > org.quartz-scheduler</groupId >
<artifactId > quartz-jobs</artifactId >
<version > 2.2.1</version >
</dependency >
定义Quartz 的Job
package common.quartz.task001;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
* @Package : common.quartz <br/>
* @Description : Quartz 任务调度程序一个 Job,实现Job 接口 <br/>
* @author : PengRong <br/>
* @Date : Created in 2018/1/9 20:52 <br/>
* @Company : PLCC <br/>
* @Copyright : Copyright (c) 2017 <br/>
* @Version : 1.0 <br/>
* @Modified By: <br/>
* @Created by PengRong on 2018/1/9. <br/>
*/
public class QuartzJob implements Job {
/**
* execute 是被调度器scheduler 到时间点调度的方法。
* @param jobExecutionContext
* @throws JobExecutionException
*/
@Override
public void execute (JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("quartzJob task 001....." );
}
}
基于不同的触发器不同测试类
package common.quartz.task001;
import org.junit.Test;
import org.quartz.CalendarIntervalScheduleBuilder;
import org.quartz.CalendarIntervalTrigger;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.DateBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.spi.MutableTrigger;
import java.util.Date;
/**
* QuartzJob Tester.
* https://www.w3cschool.cn/quartz_doc/quartz_doc-2put2clm.html 英翻译中 教程
* 该类包含一些常见调度规则配置案例;作为一个教程配置
* @author <PengRong>
* @version 1.0
*/
public class QuartzJobTest {
/**
* Method: ex