而 Quartz 2.x 版之後就改用 method chaining 的設計方式
以下為 Quartz 2.2 的簡易使用範例, 設計API的方式可作為程式寫作參考
JobDetail job = JobBuilder.newJob(Class.forName("MyJob").asSubclass(Job.class)) .withIdentity("JobName", "JobGroup") .build(); TriggerKey triggerKey = TriggerKey.triggerKey("TriggerName", "TriggerGroup"); CronTrigger trigger = TriggerBuilder.newTrigger() .withIdentity(triggerKey) .withSchedule(CronScheduleBuilder.cronSchedule("0/20 * * * * ?")) .build(); Scheduler sched = new StdSchedulerFactory().getScheduler(); sched.scheduleJob(job, trigger); sched.start();//scheduler start sched.unscheduleJob(triggerKey);//unschedule Job sched.shutdown(true);//shutdown the scheduler
0 comments:
Post a Comment