I want to dynamically add triggers to a job, but can\'t find any helpful methods off of Scheduler
I though i would just be able to call the scheduleJob method an repetit
CronTrigger trigger=null;
CronTrigger trigger1=null;
CronTrigger trigger2=null;
JobDetail job = new JobDetail();
job.setName("dummyJobName");
job.setJobClass(ExampleJob.class);
trigger = new CronTrigger();
trigger.setName("AppTrigger");
trigger.setGroup(job.getGroup());
trigger.setJobName(job.getName());
trigger.setJobGroup(job.getGroup());
trigger.setCronExpression("*/2 * * * * ?");
trigger1 = new CronTrigger();
trigger1.setName("AppTrigger1");
trigger1.setGroup(job.getGroup());
trigger1.setJobName(job.getName());
trigger1.setJobGroup(job.getGroup());
trigger1.setCronExpression("*/2 * * * * ?");
trigger2 = new CronTrigger();
trigger2.setName("AppTrigger2");
trigger2.setGroup(job.getGroup());
trigger2.setJobName(job.getName());
trigger2.setJobGroup(job.getGroup());
trigger2.setCronExpression("*/2 * * * * ?");
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.addJob(job, true);
scheduler.scheduleJob(trigger);
scheduler.scheduleJob(trigger1);
scheduler.scheduleJob(trigger2);
You can call scheduleJob repeatedly. Just make sure that you give each Trigger a unique name/group.
See TriggerBuilder.withIdentity: http://www.quartz-scheduler.org/docs/api/2.0.0/index.html
This post gives a hint, but the conclusion ( schedulerInstance.add(trigger) ) is not valid as of Quartz 2.01.
Instead use the following, after assinging the job to the trigger ( one way is using the TriggerBuilder's forJob method )
schedulerInstance.scheduleJob( newTrigger )