I want to execute multiple jobs sequentially . I am trying it in following way but somehow its not gets triggered using cron job.
I am not sure whether its a correct implementation approach . Can someone please guide me on this ?
Thanks ..
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobChainingJobListener jobListener =new JobChainingJobListener("ChainListener");
JobDetail job1 = JobBuilder.newJob(MyJob1.class)
.withIdentity(MyJob1.class.getName()).
withDescription(MyJob1.class.getName())
.build();
JobDetail job2 = JobBuilder.newJob(MyJob2.class)
.withIdentity(MyJob2.class.getName()).
withDescription(MyJob2.class.getName())
.build();
JobDetail job3 = JobBuilder.newJob(MyJob3.class)
.withIdentity(MyJob3.class.getName()).
withDescription(MyJob3.class.getName())
.build();
Trigger jobTrigger = TriggerBuilder.newTrigger()
.withIdentity("MyTrigger")
.withSchedule(CronScheduleBuilder.cronSchedule(cronTrigger)).build();
scheduler.scheduleJob(job1, jobTrigger);
scheduler.addJob(job2, true);
scheduler.addJob(job3, true);
jobListener.addJobChainLink(job1.getKey(), job2.getKey());
jobListener.addJobChainLink(job2.getKey(), job3.getKey());
scheduler.getListenerManager().addJobListener(jobListener);
scheduler.start();
After adding group name to job and trigger identity able to execute it . Here is correct code :
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobChainingJobListener jobListener =new JobChainingJobListener("ChainListener");
JobDetail job1 = JobBuilder.newJob(MyJob1.class)
.withIdentity(MyJob1.class.getName(),"BatchJobGroup").
withDescription(MyJob1.class.getName())
.build();
JobDetail job2 = JobBuilder.newJob(MyJob2.class)
.withIdentity(MyJob2.class.getName(),"BatchJobGroup").
withDescription(MyJob2.class.getName())
.build();
JobDetail job3 = JobBuilder.newJob(MyJob3.class)
.withIdentity(MyJob3.class.getName(),"BatchJobGroup").
withDescription(MyJob3.class.getName())
.build();
Trigger jobTrigger = TriggerBuilder.newTrigger()
.withIdentity("MyTrigger","BatchJobGroup").
.withSchedule(CronScheduleBuilder.cronSchedule("* * * * *")).build();
scheduler.scheduleJob(job1, jobTrigger);
scheduler.addJob(job2, true);
scheduler.addJob(job3, true);
jobListener.addJobChainLink(job1.getKey(), job2.getKey());
jobListener.addJobChainLink(job2.getKey(), job3.getKey());
scheduler.getListenerManager().addJobListener(jobListener);
scheduler.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With