How can I guarantee that only one JobInstance job is launched at a time?

Spring The batch documentation says: “Spring Batch will not try to stop them running simultaneously” (http://static.springsource.org/ spring-batch / reference / html-single / index.html).

But I would like to receive an error message if I try to start the task, and there is an instance of this work. Is it possible?

I am using Spring Package 2.1.8.

+4
source share
2 answers

If you know that a subsequent task will be queued, you can use TaskExecutor.

  • Create an executable task file with a maximum pool size, say 500

    <task:executor id="poolTaskExecutor" pool-size="500"/> 
  • ThrottledTaskexecutor

    ThrottledTaskExecutor will only pass a given number of tasks at a time above poolTaskExecutor. This class can be found below on spring github, or you can download the maven artifact. https://github.com/SpringSource/spring-batch-admin/blob/master/spring-batch-admin-manager/src/main/java/org/springframework/batch/admin/util/ThrottledTaskExecutor.java

  • ThrottledTaskExecutor Instant

     <bean id="throttledTaskExecutor" class="org.springframework.batch.admin.util.ThrottledTaskExecutor"> <property name="taskExecutor" ref="poolTaskExecutor" /> <property name="throttleLimit" value="1"/> </bean> 
  • ThrottledJobLauncher

     <bean id="throttledJobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> <property name="taskExecutor" ref="throttledTaskExecutor" /> </bean> 

All jobs launched using throttledJobLauncher above will only run one instance at a time. This is more flexible since you can limit one or more tasks using the throttledLimit parameter.

Actually above the definition of poolTaskExecutor and the ThrottledTaskexecutor class from spring -batch-admin. This is a great feature. You just need to define a ThrottledTaskExecutor with a limit and include in your jobLauncher your work.

+5
source

you can check

 jobExecution.getStatus() 

as described in

fooobar.com/questions/1402437 / ...

+2
source

Source: https://habr.com/ru/post/1402433/


All Articles