Skip to content

Commit

Permalink
To enable multiple execution of a job with the same parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hamedmirzaei committed May 7, 2019
1 parent e4abb5a commit 4d85678
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spring-batch/src/main/java/org/baeldung/batch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;

Expand All @@ -21,7 +22,11 @@ public static void main(final String[] args) {
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) {
Expand Down

0 comments on commit 4d85678

Please sign in to comment.