diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/EndState.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/EndState.java index 5dda8130a..99e25a3b6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/EndState.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/EndState.java @@ -37,10 +37,12 @@ public class EndState extends AbstractState { JobExecution jobExecution = executor.getJobExecution(); // If there are no step executions, then we are at the beginning of a // restart - if (!jobExecution.getStepExecutions().isEmpty()) { - jobExecution.upgradeStatus(status); + synchronized (jobExecution) { + if (!jobExecution.getStepExecutions().isEmpty()) { + jobExecution.upgradeStatus(status); + } + return FlowExecution.COMPLETED; } - return FlowExecution.COMPLETED; } } \ No newline at end of file diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java index 401ac3373..4bd50dc4a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/PauseState.java @@ -26,15 +26,16 @@ public class PauseState extends AbstractState { // This state is just a toggle for the status of the job execution. If // not already paused we pause it, and expect the flow to respect the // status. - if (!jobExecution.isPaused()) { - jobExecution.pause(); - return FlowExecution.PAUSED; - } - - // ...otherwise set the status to show that it has resumed - jobExecution.setStatus(BatchStatus.STARTED); - return FlowExecution.COMPLETED; + synchronized (jobExecution) { + if (!jobExecution.isPaused()) { + jobExecution.pause(); + return FlowExecution.PAUSED; + } + // ...otherwise set the status to show that it has resumed + jobExecution.setStatus(BatchStatus.STARTED); + return FlowExecution.COMPLETED; + } } } \ No newline at end of file