Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Regarding the documentation http://docs.spring.io/spring-batch/reference/htmlsingle/#d5e1320
"If the process died ("kill -9" or server failure) the job is, of course, not running, but the JobRepository has no way of knowing because no-one told it before the process died."
I try to find and restart the stale job executions by using
Set<JobExecution> jobExecutions = jobExplorer.findRunningJobExecutions(jobName); ... jobExecution.setStatus(FAILED); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); jobOperator.restart(jobExecution.getId());
But this seems to be very inconvenient. 1) I have to do this before other (new) jobs could be started. 2) I have to handle multiple instances of running servers so findRunningJobExecutions will not do the trick.
You can find other questions regarding this topic: https://jira.spring.io/browse/BATCH-2433?jql=project%20%3D%20BATCH%20AND%20status%20%3D%20Open%20ORDER%20BY%20priority%20DESC Spring Batch after JVM crash
I would love to see a solution to register a "start up clean jobs listener". This will still not fix the problems originated by the multi server environment because spring batch does not know if the JobExecution marked by STARTED is not running on an other instance.
Mahmoud Ben Hassine commented
Yes, as mentioned in the section of the docs you linked, "it's a business decision and there is no way to automate it". So you need to manually mark the job execution as failed or abandoned.
The job repository acts a central guard in a clustered environment to prevent launching the same job instance on different servers. So