Skip to content

Commit 6a086ff

Browse files
committed
BlockingCell's uninterruptibleGet calls now restore the interrupt flag if interrupted during their execution.
1 parent 9ef9733 commit 6a086ff

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/main/java/com/rabbitmq/utility/BlockingCell.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,19 @@ public synchronized T get(long timeout) throws InterruptedException, TimeoutExce
8383
* @return the waited-for value
8484
*/
8585
public synchronized T uninterruptibleGet() {
86-
while (true) {
87-
try {
88-
return get();
89-
} catch (InterruptedException ex) {
90-
// no special handling necessary
86+
boolean wasInterrupted = false;
87+
try {
88+
while (true) {
89+
try {
90+
return get();
91+
} catch (InterruptedException ex) {
92+
// no special handling necessary
93+
wasInterrupted = true;
94+
}
9195
}
96+
} finally {
97+
if (wasInterrupted)
98+
Thread.currentThread().interrupt();
9299
}
93100
}
94101

@@ -104,14 +111,20 @@ public synchronized T uninterruptibleGet() {
104111
public synchronized T uninterruptibleGet(int timeout) throws TimeoutException {
105112
long now = System.nanoTime() / NANOS_IN_MILLI;
106113
long runTime = now + timeout;
107-
108-
do {
109-
try {
110-
return get(runTime - now);
111-
} catch (InterruptedException e) {
112-
// Ignore.
113-
}
114-
} while ((timeout == INFINITY) || ((now = System.nanoTime() / NANOS_IN_MILLI) < runTime));
114+
boolean wasInterrupted = false;
115+
try {
116+
do {
117+
try {
118+
return get(runTime - now);
119+
} catch (InterruptedException e) {
120+
// Ignore.
121+
wasInterrupted = true;
122+
}
123+
} while ((timeout == INFINITY) || ((now = System.nanoTime() / NANOS_IN_MILLI) < runTime));
124+
} finally {
125+
if (wasInterrupted)
126+
Thread.currentThread().interrupt();
127+
}
115128

116129
throw new TimeoutException();
117130
}

0 commit comments

Comments
 (0)