一、Jar包依赖
org.quartz-scheduler
quartz
2.2.2
二、创建自己的Job类,实现 org.quartz.Job 类
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class MyJob implements Job {
public void execute(JobExecutionContext arg0) throws JobExecutionException {
Date date = new Date();
System.out.println(date.toString());
}
}
三、Main函数中创建轮询任务,并设置轮询的时间间隔
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
public class Application