Fixed run lockings
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
f7876dc964
commit
159805701c
@ -155,7 +155,7 @@ public final class ReadingRunnable implements Runnable {
|
||||
.getLogger(ReadingRunnable.class.getName());
|
||||
|
||||
/** Read messages. */
|
||||
private final Deque<String> messages = new ArrayDeque<>();
|
||||
private final Deque<String> messages = new ArrayDeque<>();
|
||||
|
||||
/** the reader. */
|
||||
private final BufferedReader reader;
|
||||
@ -170,7 +170,7 @@ public final class ReadingRunnable implements Runnable {
|
||||
/** The lock. */
|
||||
private final Object messageBlockerLock = new Object();
|
||||
/** The message being delivered. */
|
||||
private String delivering;
|
||||
private String delivering;
|
||||
|
||||
/** Create a reading runnable.
|
||||
*
|
||||
@ -320,12 +320,19 @@ public final class ReadingRunnable implements Runnable {
|
||||
* @see java.lang.Runnable#run() */
|
||||
@Override
|
||||
public void run() {
|
||||
while (running) {
|
||||
boolean cont = true;
|
||||
while (cont) {
|
||||
synchronized (lock) {
|
||||
cont = running;
|
||||
if (!running) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
String line = reader.readLine();
|
||||
if (line == null) {
|
||||
// Buffer end
|
||||
running = false;
|
||||
setRunning(false);
|
||||
return;
|
||||
}
|
||||
LOGGER.finer("Read: " + line); //$NON-NLS-1$
|
||||
@ -335,17 +342,21 @@ public final class ReadingRunnable implements Runnable {
|
||||
lock.notifyAll();
|
||||
}
|
||||
} catch (final InterruptedIOException e) {
|
||||
if (running) {
|
||||
LOGGER.info("Reading interrupted"); //$NON-NLS-1$
|
||||
synchronized (lock) {
|
||||
if (running) {
|
||||
LOGGER.info("Reading interrupted"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
LOGGER.log(Level.FINER, "Read interruption was caused by an exception", //$NON-NLS-1$
|
||||
e);
|
||||
} catch (final IOException e) {
|
||||
LOGGER.log(Level.FINE, "The stream reading threw an exception", //$NON-NLS-1$
|
||||
e);
|
||||
if (running) {
|
||||
LOGGER.severe("Unable to read from stream"); //$NON-NLS-1$
|
||||
running = false;
|
||||
synchronized (lock) {
|
||||
if (running) {
|
||||
LOGGER.severe("Unable to read from stream"); //$NON-NLS-1$
|
||||
setRunning(false);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -171,8 +171,10 @@ public final class WritingRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
if (running) {
|
||||
LOGGER.log(Level.SEVERE, "Thread interruption exception.", e); //$NON-NLS-1$
|
||||
synchronized (lock) {
|
||||
if (running) {
|
||||
LOGGER.log(Level.SEVERE, "Thread interruption exception.", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user