To enable multiple execution of a job with the same parameters

This commit is contained in:
Hamed Mirzaei 2019-05-07 10:22:42 +04:30
parent e4abb5af73
commit 4d85678e96
1 changed files with 6 additions and 1 deletions

View File

@ -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) {