I'm using spring.batch.core's JobExecution. And I'm using JobExecutionListenerSupport's overridden method afterJob like this
@Override
public void afterJob(JobExecution jobExecution) {
if (jobExecution.getStatus() == BatchStatus.FAILED) {
log.error();
throw new AbortingJobException();
} else if (jobExecution.getStatus() == BatchStatus.STOPPED) {
log.info(jobExecution.getJobInstance().getJobName() + " Stopped");
} else if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
// does something
}
}
I want to know when does jobExecution.getStatus() == BatchStatus.STOPPED
become true?
This blog also helps in answering it. [https://blog.codecentric.de/en/2014/04/spring-batch-batchstatus-state-transitions/]
The BatchStatus of the job is set to STOPPING, and steps will check for this state at chunk boundaries to stop themselves. When all steps are stopped, the state of the job is set to STOPPED as well. This means that if a step is looping inside a chunk, or if the server is shut down during stopping the batch, the job will always stay in state STOPPING.