Skip to content

Commit 9b5e7a2

Browse files
committed
BATCH-2156: blocking when the ExecutionContext is updated to prevent transaction serialization issues
1 parent dc1a5fc commit 9b5e7a2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,18 @@ public void updateExecutionContext(final JobExecution jobExecution) {
148148

149149
@Override
150150
public void updateExecutionContext(final StepExecution stepExecution) {
151+
// Attempt to prevent concurrent modification errors by blocking here if
152+
// someone is already trying to do it.
153+
synchronized (stepExecution) {
154+
Long executionId = stepExecution.getId();
155+
ExecutionContext executionContext = stepExecution.getExecutionContext();
156+
Assert.notNull(executionId, "ExecutionId must not be null.");
157+
Assert.notNull(executionContext, "The ExecutionContext must not be null.");
151158

152-
Long executionId = stepExecution.getId();
153-
ExecutionContext executionContext = stepExecution.getExecutionContext();
154-
Assert.notNull(executionId, "ExecutionId must not be null.");
155-
Assert.notNull(executionContext, "The ExecutionContext must not be null.");
156-
157-
String serializedContext = serializeContext(executionContext);
159+
String serializedContext = serializeContext(executionContext);
158160

159-
persistSerializedContext(executionId, serializedContext, UPDATE_STEP_EXECUTION_CONTEXT);
161+
persistSerializedContext(executionId, serializedContext, UPDATE_STEP_EXECUTION_CONTEXT);
162+
}
160163
}
161164

162165
@Override

0 commit comments

Comments
 (0)