简体   繁体   中英

Spring Batch Job dependency

I am new to Spring Batch. I have a requirement to schedule multiple jobs where one job is dependent on completion of other job. In Spring Batch I found that it is very easy to put step dependency. Is there any way to make one job dependent on other job?

You could use a JobExecutionListener.afterJob and run the other job based on the outcome of the first. See the docs for more details.

But it might make more sense to configure a new job that encompasses all these steps and re-uses the existing steps in that job.

Spring Batch does not provide a way to have dependency between jobs. However ideal way to achieve this is how you are invoking the jobs. This can be easily achieved using Quartz scheduler.

Or can be done like this.

ApplicationContext context = new ClassPathXmlApplicationContext(config);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job1 = (Job) context.getBean("testJob");
Job job2 = (Job) context.getBean("testJob2");


JobExecution execution1 = jobLauncher.run(job1, new JobParameters());
System.out.println("Exit Status : " + execution1.getStatus());
if(execution1.getStatus()==0){
     JobExecution execution2 = jobLauncher.run(job2, new JobParameters());
     System.out.println("Exit Status : " + execution2.getStatus());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM