From 9b5e7a281ecefcbc589c90eb27bc05c36998bb78 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Wed, 26 Mar 2014 16:41:24 -0500 Subject: [PATCH] BATCH-2156: blocking when the ExecutionContext is updated to prevent transaction serialization issues --- .../repository/dao/JdbcExecutionContextDao.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java index f69a2a21c..c6365efb9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java @@ -148,15 +148,18 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem @Override public void updateExecutionContext(final StepExecution stepExecution) { + // Attempt to prevent concurrent modification errors by blocking here if + // someone is already trying to do it. + synchronized (stepExecution) { + Long executionId = stepExecution.getId(); + ExecutionContext executionContext = stepExecution.getExecutionContext(); + Assert.notNull(executionId, "ExecutionId must not be null."); + Assert.notNull(executionContext, "The ExecutionContext must not be null."); - Long executionId = stepExecution.getId(); - ExecutionContext executionContext = stepExecution.getExecutionContext(); - Assert.notNull(executionId, "ExecutionId must not be null."); - Assert.notNull(executionContext, "The ExecutionContext must not be null."); + String serializedContext = serializeContext(executionContext); - String serializedContext = serializeContext(executionContext); - - persistSerializedContext(executionId, serializedContext, UPDATE_STEP_EXECUTION_CONTEXT); + persistSerializedContext(executionId, serializedContext, UPDATE_STEP_EXECUTION_CONTEXT); + } } @Override