quartz编码方式添加Job和Trigger
// 获取调度对象Scheduler scheduler = (Scheduler) SpringContextUtil.getBean("scheduler");
String jobName = "testJob";
String trigName = "testTrigger";
// 添加Job
JobBuilder jb =JobBuilder.newJob(TestJob.class);
jb.withIdentity(jobName, schedGroup);
jb.storeDurably();
jb.withDescription(acquisitionTask.getRemark());
JobDetail jobDetail= jb.build();
jobDetail.getJobDataMap().put("data", testData);
scheduler.addJob(jobDetail, true);
// 添加Cron形式的Trigger
JobKey jobKey=new JobKey(jobName, schedGroup);
TriggerBuilder<Trigger> tb=TriggerBuilder.newTrigger();
tb.withIdentity(trigName,schedGroup);
ScheduleBuilder sb=CronScheduleBuilder.cronSchedule(corn);
tb.startNow();
tb.withSchedule(sb);
tb.withDescription("描述");
tb.forJob(jobKey);
Trigger trig=tb.build();
scheduler.scheduleJob(trig);
项目中用到了相关内容,在此记录一下
页:
[1]