diff --git a/spring-batch-infrastructure/.classpath b/spring-batch-infrastructure/.classpath index 617809812..4ac7c0449 100644 --- a/spring-batch-infrastructure/.classpath +++ b/spring-batch-infrastructure/.classpath @@ -1,9 +1,9 @@ - - + + - + diff --git a/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs b/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs index 2506d00a3..88dfc41ab 100644 --- a/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs +++ b/spring-batch-infrastructure/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,12 @@ -#Wed Sep 09 08:10:50 BST 2009 +#Sat Sep 19 10:54:53 BST 2009 eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java index f8edcd09e..b391e456e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueue.java @@ -19,6 +19,7 @@ package org.springframework.batch.repeat.support; import java.util.NoSuchElementException; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.Semaphore; /** * An implementation of the {@link ResultQueue} that throttles the number of @@ -32,21 +33,19 @@ public class ThrottleLimitResultQueue implements ResultQueue { private final BlockingQueue results; // Accumulation of dummy objects flagging expected results in the future. - private volatile int waits = 0; + private final Semaphore waits; private final Object lock = new Object(); private volatile int count = 0; - private final int throttleLimit; - /** * @param throttleLimit the maximum number of results that can be expected * at any given time. */ public ThrottleLimitResultQueue(int throttleLimit) { - this.throttleLimit = throttleLimit; results = new LinkedBlockingQueue(); + waits = new Semaphore(throttleLimit); } public boolean isEmpty() { @@ -61,7 +60,7 @@ public class ThrottleLimitResultQueue implements ResultQueue { public boolean isExpecting() { // Base the decision about whether we expect more results on a // counter of the number of expected results actually collected. - // Do not synchronize! Otherwise put and expect can deadlock. + // Do not synchronize! Otherwise put and expect can deadlock. return count > 0; } @@ -74,10 +73,7 @@ public class ThrottleLimitResultQueue implements ResultQueue { */ public void expect() throws InterruptedException { synchronized (lock) { - while (waits >= throttleLimit) { - lock.wait(); - } - waits++; + waits.acquire(); count++; } } @@ -88,12 +84,9 @@ public class ThrottleLimitResultQueue implements ResultQueue { } // There should be no need to block here, or to use offer() results.add(holder); - // Take from the waits now to allow another result to + // Take from the waits queue now to allow another result to // accumulate. But don't decrement the counter. - synchronized (lock) { - waits--; - lock.notifyAll(); - } + waits.release(); } public T take() throws NoSuchElementException, InterruptedException {