From 012e2634f8e7d58217624dfae905fe670d30fd20 Mon Sep 17 00:00:00 2001 From: dsyer Date: Sat, 9 Feb 2008 15:09:05 +0000 Subject: [PATCH] Incomplete - task 79: Failed build with queue in repeat template Prevent race that fails CI build sometimes by making put() atomic. --- .../support/TaskExecutorRepeatTemplate.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java index fafde4ed2..80f84b514 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java @@ -272,6 +272,9 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { // Arbitrary lock object. private Object lock = new Object(); + // Arbitrary lock object. + private Object hold = new Object(); + // Counter to monitor the difference between expected and actually // collected results. When this reaches zero there are really no more // results. @@ -303,13 +306,15 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { } public void put(ResultHolder holder) { - // There should be no need to block here, or to use offer(): - // TODO: fix race condition where many calls come into put() at once - // and the queue fills up... - results.add(holder); - // Take from the waits queue now to allow another result to - // accumulate. But don't decrement the counter. - waits.release(); + // There should be no need to block here, or to use offer(), but + // apparently the add() sometimes takes so long on the CI build that + // the queue fills up... + synchronized (hold) { + results.add(holder); + // Take from the waits queue now to allow another result to + // accumulate. But don't decrement the counter. + waits.release(); + } } public ResultHolder take() {