8

I have a clarification.

Is it possible for us to run multiple instances of a job at the same time.

Currently, we have single instance of a job at any given time.

If it is possible, please let me know how to do it.

Anand Kumar
  • 133
  • 2
  • 4
  • 10

3 Answers3

11

Yes you can. Spring Batch distinguishes jobs based on the JobParameters. So if you always pass different JobParameters to the same job, you will have multiple instances of the same job running. A simple way is just to add a UUID parameter to each request to start a job. Example:

final JobParametersBuilder jobParametersBuilder = new JobParametersBuilder();
jobParametersBuilder.addString("instance_id", UUID.randomUUID().toString(), true);
jobLauncher.run(job,jobParametersBuilder.toJobParameters());

The boolean 'true' at the end signal to Spring Batch to use that parameter as part of the 'identity' of the instance of the job, so you will always get new instances with each 'run' of the job.

Antonio Dias
  • 319
  • 3
  • 17
1

Yes you can very much run tasks in parallel as also documented here

But there are certain things to be considered

  • Does your application logic needs parallel execution? Because if if you are going to run steps in parallel, you would have to take care and build application logic so that the work done by parallel steps is not overlapping (Unless that is the intention of your application)
Vishal Biyani
  • 4,297
  • 28
  • 55
  • This is an old question, but I want to clarify that the OP is asking if "multiple instances of [the same] job" can be run in parallel. The link you provided refers to running steps within a single execution in parallel which is a different concept. – IcedDante May 10 '16 at 18:54
0

Yes, it's completely possible to have multiple instances (or executions) of a job run concurrently.

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73