quartz 首页的几行代码

来源:互联网 发布:贴吧顶贴软件 谭队 编辑:程序博客网 时间:2024/06/05 22:57

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);

0 0
原创粉丝点击