标签:sch 触发器 scheduler class blog rom off hint second
1.官网学习
地址:http://www.quartz-scheduler.org/
官网上有说明文档及示例,帮助你更好的使用API
2.学习总结
2.1 任务管理(启动,关闭)等操作是依靠调度器Scheduler来管理的,而Scheduler实例是通过工厂Factory获取的,调度器调用了.start()方法,才会让其管理的任务执行
// Grab the Scheduler instance from the Factory Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); // and start it off scheduler.start();
2.2 创建任务实体类,你需要实现接口org.quartz.Job,并覆写其.execute()方法,调度器调度任务时就是执行其execute()方法
public class MyJob implements org.quartz.Job { public MyJob() { } public void execute(JobExecutionContext context) throws JobExecutionException { System.err.println("Hello World! MyJob is executing."); } }
2.3 调度器scheduler通过触发器trigger来管理任务job,来确定何时任务应该执行,如每间隔多少秒执行一次等
// 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);
2.4
2.5
2.6
2.7
标签:sch 触发器 scheduler class blog rom off hint second
原文地址:http://www.cnblogs.com/gsonkeno/p/6663346.html