csjr
csjr

Reputation: 136

Spring Batch Generic Job Design

I'm having trouble finding the correct answer to this question. When using Spring Batch framework is it ok to try to solve all the batch processing in one generic job?

For instance, I'm trying to process different text files (files with a different structure) with the same job.

My idea is to run the job from a scheduler passing to it a String with the name of the file I want to process. Then, I would be able to instantiate an object related to the file to be processed, and this object will be passed from one step to the other and in each step, it would be able to answer questions related to its delimiters, fields names, insert statement, so on and so forth.

On the other hand, I could write a job for each file, but a lot of code would be repeated.

Upvotes: 0

Views: 1304

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31600

JobStep is what you might need. It is a special step that delegates to a job. Hence you can design a "master" job with several sub-jobs (aka steps of type JobStep). Obviously, each sub-job can be a regular Spring Batch job with its steps, etc. The master job in this approach is the "one generic job" you are looking for.

this object will be passed from one step to the other and in each step

This is possible by passing the object (for example the file name) in the execution context from one step to the next one. You can find more details about this approach as well as a code example in the Passing Data to Future Steps.

Hope this helps.

Upvotes: 1

Related Questions