Java – Best approach to chain two jobs one after another using Spring Batch


I am having two jobs(Job1,Job2)
Job2 is depended on the results of job1 so it has to wait till job 1 finished

I need to chain them somehow:

  1. When job1 finish it needs to call job2. how to do that? using tasklet in the end which will call job2?

  2. The other way could be that the invoker(which is some scheduler service) will be responsible for calling job2 as soon as job1 returns – not really good because than ill need to call job1 synchronously.

How would you implement two chained (and depended jobs) using spring batch?

Thank you.

Best Solution

You can use a JobStep to launch the second job from within the first job. See 5.3.6 Externalizing Flow Definitions and Dependencies Between Jobs

Related Question