Skip to content

Commit abff748

Browse files
authored
Merge pull request eugenp#6908 from hamedmirzaei/master
To enable multiple execution of a job with the same parameters
2 parents 18bd06a + 4d85678 commit abff748

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • spring-batch/src/main/java/org/baeldung/batch

spring-batch/src/main/java/org/baeldung/batch/App.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.springframework.batch.core.Job;
44
import org.springframework.batch.core.JobExecution;
55
import org.springframework.batch.core.JobParameters;
6+
import org.springframework.batch.core.JobParametersBuilder;
67
import org.springframework.batch.core.launch.JobLauncher;
78
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
89

@@ -21,7 +22,11 @@ public static void main(final String[] args) {
2122
final Job job = (Job) context.getBean("firstBatchJob");
2223
System.out.println("Starting the batch job");
2324
try {
24-
final JobExecution execution = jobLauncher.run(job, new JobParameters());
25+
// To enable multiple execution of a job with the same parameters
26+
JobParameters jobParameters = new JobParametersBuilder()
27+
.addString("jobID", String.valueOf(System.currentTimeMillis()))
28+
.toJobParameters();
29+
final JobExecution execution = jobLauncher.run(job, jobParameters);
2530
System.out.println("Job Status : " + execution.getStatus());
2631
System.out.println("Job succeeded");
2732
} catch (final Exception e) {

0 commit comments

Comments
 (0)