Fixed run lockings

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2018-10-11 12:42:14 -04:00
parent f7876dc964
commit 159805701c
2 changed files with 24 additions and 11 deletions

View File

@ -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) {
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);
synchronized (lock) {
if (running) {
LOGGER.severe("Unable to read from stream"); //$NON-NLS-1$
running = false;
setRunning(false);
}
}
return;
}

View File

@ -171,9 +171,11 @@ public final class WritingRunnable implements Runnable {
}
}
} catch (final InterruptedException e) {
synchronized (lock) {
if (running) {
LOGGER.log(Level.SEVERE, "Thread interruption exception.", e); //$NON-NLS-1$
}
}
Thread.currentThread().interrupt();
}
}