From 655594c34b391cc602b5656e2b4169b968d18fff Mon Sep 17 00:00:00 2001
From: Philippe M
Date: Tue, 13 Aug 2013 22:47:15 +0200
Subject: [PATCH] Fix for BATCH-1767
---
.../batch/core/step/tasklet/TaskletStep.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java
index 7cca3e0af1..7a4712f647 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java
@@ -392,11 +392,6 @@ public Object doInTransaction(TransactionStatus status) {
chunkListener.beforeChunk(chunkContext);
- // In case we need to push it back to its old value
- // after a commit fails...
- oldVersion = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution());
- copy(stepExecution, oldVersion);
-
try {
try {
@@ -422,6 +417,13 @@ public Object doInTransaction(TransactionStatus status) {
try {
semaphore.acquire();
locked = true;
+ // In case we need to push it back to its old value
+ // after a commit fails...
+ // Here we are sure we get the most up to date version since
+ // semaphore acquisition garantees that no other thread has modified it
+ oldVersion = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution());
+ copy(stepExecution, oldVersion);
+
}
catch (InterruptedException e) {
logger.error("Thread interrupted while locking for repository update");