Skip to content

Commit 2ac2e62

Browse files
author
Simon MacMullen
committed
Guard against spurious wakeups in BlockingCell.get(long).
1 parent b5302a1 commit 2ac2e62

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/com/rabbitmq/utility/BlockingCell.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,17 @@ public synchronized T get() throws InterruptedException {
7676
* @throws InterruptedException if this thread is interrupted
7777
*/
7878
public synchronized T get(long timeout) throws InterruptedException, TimeoutException {
79-
if (timeout < 0 && timeout != INFINITY)
79+
if (timeout == INFINITY) return get();
80+
81+
if (timeout < 0)
8082
throw new AssertionError("Timeout cannot be less than zero");
8183

8284
if (!_filled && timeout != 0) {
83-
wait(timeout == INFINITY ? 0 : timeout);
85+
long maxTime = System.currentTimeMillis() + timeout;
86+
long now;
87+
while ((now = System.currentTimeMillis()) < maxTime) {
88+
wait(maxTime - now);
89+
}
8490
}
8591

8692
if (!_filled)

0 commit comments

Comments
 (0)