Spring Batch - Executing multiple instances of a job at same time

自古美人都是妖i 提交于 2019-12-10 17:09:58

问题


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.


回答1:


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.




回答2:


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)



回答3:


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



来源:https://stackoverflow.com/questions/10948605/spring-batch-executing-multiple-instances-of-a-job-at-same-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!