2
votes

Spring Batch jobs I have multiple jobs to be executed sequentially. I need to pass results of job1 to job2 where it will be processed and then pass the data of job2 to job3. and so on. and may use results of job1 till job5(last job) and write output.

Job1 - is reading from db and and storing results in Hashmap Job2 read from file and use the job1 hashmap for procesing results.

So please can anyone suggest the best solution for this. I am able to pass data between steps using ExecutionContext & JobPromotionListener, but not sure how to do same between multiple jobs

2
Batch jobs are meant to be time driven rather than event driven (as described in your case, when Job1 finishes, execute Job2). It is impossible to communicate b/w two batch jobs like client server model. You probably should try to store the Job1 results in some file or DB table where Job2 has access to it and schedule you jobs with enough time difference.Utkarsh
Why do you need these to be different jobs? Wouldn't it make more sense to have one job with multiple processors?beny23
Thank you for responding, I think we will go with using multiple stepslakshmi

2 Answers

1
votes

Instead of having 5 jobs for your batch processing you should have 5 steps of the same job. It is the best way to perform what you are trying to achieve.

Spring Batch framework keeps the state of every step execution so in case one of your steps fails you can relaunch your job that will only process remaining steps. Of course there are customisation options to control how and when a step can be considered failing or relaunchable.

0
votes

Spring batch does not provide out of box support for the same.Seems like all you need is to configure some steps that can be executed sequentially.you can also divide the steps using the readers ,processor and writers