package quartz;
import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
public class FirstQuartzDemo implements Job{
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("FirstQuartzDemo");
}
public static void main(String[] args) throws SchedulerException {
/**
* Step1:建立Job
*/
JobDetail jd = JobBuilder.newJob(FirstQuartzDemo.class)
.withDescription("my first quartz demo")
.withIdentity("first").build();
/**
* Step2:建立trigger
*/
Trigger trigger = TriggerBuilder.newTrigger()
.withSchedule(
SimpleScheduleBuilder
.simpleSchedule()
.withIntervalInSeconds(2)
.repeatForever())
.build();
/**
* Step3:获取Scheduler
*/
StdSchedulerFactory std = new StdSchedulerFactory();
Scheduler schdl = std.getScheduler();
/**
* Step4:组装构件,实现逻辑
*/
schdl.scheduleJob(jd,trigger);
schdl.startDelayed(5);
}
}