To enable multiple execution of a job with the same parameters
@@ -3,6 +3,7 @@ package org.baeldung.batch;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
+import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -21,7 +22,11 @@ public class App {
final Job job = (Job) context.getBean("firstBatchJob");
System.out.println("Starting the batch job");
try {
- final JobExecution execution = jobLauncher.run(job, new JobParameters());
+ // To enable multiple execution of a job with the same parameters
+ JobParameters jobParameters = new JobParametersBuilder()
+ .addString("jobID", String.valueOf(System.currentTimeMillis()))
+ .toJobParameters();
+ final JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("Job Status : " + execution.getStatus());
System.out.println("Job succeeded");
} catch (final Exception e) {
