1、启动scheduler
// Grab the Scheduler instance from the Factory
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
// and start it off
scheduler.start();
2、实现你的job
public class MyJob implements org.quartz.Job {
public MyJob() {
}
public void execute(JobExecutionContext context) throws JobExecutionException {
System.err.println("Hello World! MyJob is executing.");
}
}
3、组装jobDetail、trigger、放入scheduler
// define the job and tie it to our MyJob class
JobDetail job = newJob(MyJob.class)
.withIdentity(“job1”, “group1”)
.build();
// Trigger the job to run now, and then repeat every 40 seconds
Trigger trigger = newTrigger()
.withIdentity(“trigger1”, “group1”)
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(40)
.repeatForever())
.build();
// Tell quartz to schedule the job using our trigger
scheduler.scheduleJob(job, trigger);