Hi, Matthew
Spring Batch provides a function to be able to relaunch a Batch job with the sample JobParameters as it creates new JobInstance that has same Biz JobParameters plus an unique JobParameter like 'run.id' created by JobParametersIncrementer like RunIdIncrementer.
Firstly, RunIdIncrementer out of the box of Spring Batch should be set in your Batch Job configuration as follows.
Code:
<bean id="runIdIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>
You can change the parameter key name 'run.id' to other key by setting <property name="key" value="run.count"/>.
Anyway,
Code:
<job id="BatchJob" incrementer="runIdIncrementer">
...
</job>
After configuring it, if you use CommandLineJobRunner to run Batch Jobs, you can perform the JobRunner with the option named '-next' and BIZ JobParameters. (e.g. TEST1, TEST2 and TEST3 are dependent on certain Batch Job.)
Code:
CommandLineJobRunner -next /sample/batch/BatchJob.xml BatchJob TEST1=1 TEST2=2 TEST3=3
At the first time when performing the Job, the JobParameters are created in the 'BATCH_JOB_PARAMS' spring batch table.
Code:
TEST1=1;TEST2=2;TEST3=3;run.id=1
And then this BatchJob finishes whether the BatchStatus of it is 'FAILED' or 'COMPLETED'.
From next time when executing the Job with the same JobParameters, you can see them at the table below.
Code:
TEST1=1;TEST2=2;TEST3=3;run.id=2
TEST1=1;TEST2=2;TEST3=3;run.id=3
TEST1=1;TEST2=2;TEST3=3;run.id=4
...
From what has mentioned above, you can re-run your BatchJobs with the sample jobParameters by using RunIdIncrementer.
On the other hand, in terms of BatchController Service based on web apps to perform BatchJobs of request from BatchClient by http, you can call startNextInstance(jobName) method of SimpleJobOperator class to be able to re-run them.
I think you can understand machenism of JobParametersInrementer's operation in more detaill, refer to CommandLineJobRunner and SimpleJobOperator sources.