[fix] Put wait in while loops to consider spurious interruptions.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
63de5448de
commit
2ece273148
@ -156,8 +156,11 @@ public abstract class AOutputForwardRunnable implements Runnable {
|
||||
/** a method to wait some time. */
|
||||
protected final void waitASec() {
|
||||
try {
|
||||
final long tic = System.currentTimeMillis();
|
||||
synchronized (this) {
|
||||
wait(timeout);
|
||||
while (System.currentTimeMillis() - tic < timeout) {
|
||||
wait(timeout + tic - System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$
|
||||
|
@ -128,8 +128,11 @@ public final class ReadingRunnable implements Runnable {
|
||||
* @throws IOException if the runnable was stopped and no essage was found. */
|
||||
private void doWaitMessage(final long timeout) throws IOException {
|
||||
try {
|
||||
final long tic = System.currentTimeMillis();
|
||||
synchronized (lock) {
|
||||
lock.wait(timeout);
|
||||
while (System.currentTimeMillis() - tic < timeout && messages.isEmpty()) {
|
||||
lock.wait(timeout);
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION, e);
|
||||
@ -205,7 +208,9 @@ public final class ReadingRunnable implements Runnable {
|
||||
mLock = messageBlocker.get(message);
|
||||
}
|
||||
synchronized (mLock) {
|
||||
mLock.wait();
|
||||
while (messageBlocker.containsKey(message)) {
|
||||
mLock.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,9 +256,9 @@ public final class ReadingRunnable implements Runnable {
|
||||
final Object mLock = messageBlocker.get(message);
|
||||
if (mLock!=null) {
|
||||
synchronized (mLock) {
|
||||
messageBlocker.remove(message);
|
||||
mLock.notifyAll();
|
||||
}
|
||||
messageBlocker.remove(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user