diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index 808f1c4509..f5e1954fde 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -359,6 +359,12 @@ public final void execute(JobExecution execution) { execution.setExitStatus(exitStatus.and(newExitStatus)); } + try { + listener.afterJob(execution); + } catch (Exception e) { + logger.error("Exception encountered in afterJob callback", e); + } + timerSample.stop(BatchMetrics.createTimer("job", "Job duration", Tag.of("name", execution.getJobInstance().getJobName()), Tag.of("status", execution.getExitStatus().getExitCode()) @@ -366,12 +372,6 @@ public final void execute(JobExecution execution) { longTaskTimerSample.stop(); execution.setEndTime(new Date()); - try { - listener.afterJob(execution); - } catch (Exception e) { - logger.error("Exception encountered in afterJob callback", e); - } - jobRepository.update(execution); } finally { JobSynchronizationManager.release();