Hello everybody,
i have tried to schedule 2 chained jobs with different triggers
Code:
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
JobDetail job = JobBuilder.newJob(TestJob.class)
.withIdentity("job1", "firstJobGroup").build();
//first job runs when seconds = 30
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("firstJobTrigger", "firstJobbTriggerGroup")
.withSchedule(
CronScheduleBuilder.cronSchedule("30 * * * * ?")).build();
job.getJobDataMap().put( "job1", 1 );
JobDetail job2 = JobBuilder.newJob(TestJob.class)
.withIdentity("test2", "test2").build();
job2.getJobDataMap().put( "job2", 2 );
//second job runs only if mins=01
Trigger trigger2 = TriggerBuilder.newTrigger()
.withIdentity("testtrig2", "testrig2")
.withSchedule(
CronScheduleBuilder.cronSchedule("* 01 * * * ?")).build();
//Chain the 2 jobs
JobChainingJobListener chainListener = new JobChainingJobListener( "Chain.Naifr.Stage1.Stage2" );
chainListener.addJobChainLink( job.getKey(), job2.getKey() );
sched.scheduleJob( job, trigger );
sched.scheduleJob( job2, trigger2 );
sched.getListenerManager().addJobListener( chainListener );
sched.start();
The result is that the 2 jobs are chained ( ruens one after the other) but the 2nd one launch even when mins!=01 !
How can i do to have 2 jobs chained with different triggers?