Sequential Job Schedule using Quartz in Spring
I have three or more jobs which depends on their respective previous jobs and they will run in the sequential order. If Job 1 finished Job 2 run and when Job 2 finished Job 3 run. If any error occurred in previous Job then next triggered Jobs will not be fired. I tried to know about Job-chaining using quartz but can't able to get it through.
The Jobs sequence are as per below
Job 1 -> Job 2 -> Job 3
we defined their respective beans in quartz.xml as per below
<beans ...>
<bean name="scheduler1"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="com.abc.xyz.schedular.Scheduler1" />
<property name="durability" value="true" />
</bean>
<bean id="trigger1"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="scheduler1" />
<property name="cronExpression" value="${scheduler1.cronExpression}" />
</bean>
<bean name="scheduler2"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="com.abc.xyz.schedular.Scheduler2" />
<property name="durability" value="true" />
</bean>
<bean id="trigger2"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="scheduler2" />
<property name="cronExpression" value="${scheduler2.cronExpression}" />
</bean>
<bean name="scheduler3"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="com.abc.xyz.schedular.Scheduler3" />
<property name="durability" value="true" />
</bean>
<bean id="trigger3"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="scheduler3" />
<property name="cronExpression" value="${scheduler3.cronExpression}" />
</bean>
<bean name="jobScheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="trigger1" />
<ref bean="trigger2" />
<ref bean="trigger3" />
</list>
</property>
<property name="autoStartup" value="${jobScheduler.autoStartup}" />
</bean>
</beans>
In the above xml files the cron expressions are as follows scheduler1.cronExpression=0 1 0 * * ? , scheduler2.cronExpression=0 2 0 * * ? , scheduler3.cronExpression=0 3 0 * * ? and the jobScheduler.autoStartup=true .
The Schedular class for Scheduler1.java , Scheduler2.java , Scheduler3.java is defined below.
public class Scheduler1 implements Job {
private static final Logger log = (Logger) LogManager
.getLogger(Scheduler.class.getName());
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
try {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
/*
* doing my heavy Process
*/
} catch (Exception e) {
log.error("Error in setExpiredAllPlans Schedular1 ");
}
}
}
public class Scheduler2 implements Job {
private static final Logger log = (Logger) LogManager
.getLogger(Scheduler.class.getName());
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
try {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
/*
* doing my heavy Process
*/
} catch (Exception e) {
log.error("Error in Schedular2 ");
}
}
}
public class Scheduler3 implements Job {
private static final Logger log = (Logger) LogManager
.getLogger(Scheduler.class.getName());
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
try {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
/*
* doing my heavy Process
*/
} catch (Exception e) {
log.error("Error in setExpiredAllPlans Schedular3 ");
}
}
}
Now how would i able to chain the jobs using above configuration because sometimes these heavy process take more than 1 minute so i don't want to start the next fire job until previous job is completed. If you have any concern/clarification ,please revert me.
Thanks in advance.

Job? - heenenee