1.quartz 定时器包结构见附件
2.初始化定时器容器:
// 初始化容器
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler scheduler = null;
3.创建
触发器
CronTrigger cronTrigger = new CronTrigger(job.getGroup());
JobDetail jobDetail = new JobDetail(job.getName(),
job.getGroup(), Class.forName(job.getClassName()));
scheduler = sf.getScheduler();
cronTrigger.setJobGroup(job.getGroup());
cronTrigger.setJobName(job.getName());
4.定义执行规则
CronExpression cronExpression = new CronExpression(job.getCronExpression());
cronTrigger.setCronExpression(cronExpression);
5.添加任务
scheduler.addJob(jobDetail, true);
6.添加触发器
scheduler.scheduleJob(cronTrigger);
7.行启动、关闭等操作
scheduler.start();
- class='magplus' title='点击查看原始大小图片' />
- 大小: 194.4 KB