spring-batch
spring-batch copied to clipboard
BatchStatus#isRunning() is not consistent with JobExplorer#findRunningJobExecutions(String) or JobExecution#isRunning()
Alexis SOUMAGNE opened BATCH-2114 and commented
In STOPPING status should be considered as a "running" status. The endTime is null until job status is STOPPED. Which means that the job did not recieved interuption signal yet.
Simply the code should be :
public boolean isRunning() {
return this == STARTING || this == STARTED || this == STOPPING;
}
Affects: 2.2.2
I also encountered a problem related to this issue. That is, when launching multi jobs with same parameters in multi threads, there should be only one job can succeed, but actually, there would be more than one job can succeed.
I find it is caused by SimpleJobRepository#createJobExecution, this method uses JobExecution#isRunning(), but not BatchStatus#isRunning(). So the status STARTING is missing, since startTime of JobExecution will be set only when its status changes to STARTED.
for (JobExecution execution : executions) {
if (execution.isRunning() || execution.isStopping()) {
throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: " + jobInstance);
}
...