Command
stop () will only be active if the transaction is successful. If all of you are rolling back a rollback, your work does not stop.
I made this workaround: Create a ChunkListener and in the afterChunkError(ChunkContext chunkCtx) put method:
StepExecution stepExecution = chunkCtx.getStepContext().getStepExecution(); JobExecution jobExecution = jobExplorer.getJobExecution(stepExecution.getJobExecutionId()); if (jobExecution.getStatus().equals(BatchStatus.STOPPING)) { stepExecution.setTerminateOnly(); }
This will result in a "controlled" stop.
source share