Mar 11th, 2009, 08:43 AM
How to Repeat Job based on parameters
I want to execute my job more than once based on the input parameters. Users will pass month as Job Parameter. If they pass Jan as a month, I should repeat my job from Jan to current month as separate execution. If they are not passing Month Parameter then I should Query the database to get the last execution of this job to find the month and then repeat the same job till current month by passing month as argument to my Job.
Please help my how to do this with Spring Batch.
Mar 11th, 2009, 09:08 AM
Wrap the JobLauncher. Your version will query the database, figure out what months need to run, create JobParameters, and pass them to the delegate JobLauncher to run the specific instance of the job.
The way the framework is designed, you will not be able to use the exact same parameters if the previous execution was COMPLETED. To circumvent this, you can add an additional parameter, the current timestamp, that will ensure that the JobParameters are unique.
Mar 11th, 2009, 11:18 AM
Thanks for Quick response DHGarrette.
If I already have few JobParameters in the JobParameters object of JobLauncher Run() method, How can I add new JobParameter at run time. I did not find any method to add new JobParameter to the existing JobParameters object.
I am trying to convert the given JobParameters object into Properties using DefaultJobParametersConverter and then adding new value to the Properties object and then converting it back to JobParameters object. Is it the right approach. Please let me know.
Mar 11th, 2009, 11:28 AM
Take a look at the JobParametersBuilder. It should make things easier.
Mar 12th, 2009, 02:48 AM
Also look at the JobParametersIncrementer and JobOperator interfaces (notably startNextInstance()).
Tags for this Thread