Synchronization organisation
This commit is contained in:
parent
98d22782c1
commit
761d640f0b
@ -265,6 +265,7 @@ public final class ReadingRunnable implements Runnable {
|
||||
message);
|
||||
final Thread th = new Thread(waitRunn);
|
||||
|
||||
// Wait for the thread to actually start before unlocking the message queue.
|
||||
synchronized (start) {
|
||||
th.start();
|
||||
while (!waitRunn.isStarted()) {
|
||||
|
@ -143,15 +143,14 @@ public final class WritingRunnable implements Runnable {
|
||||
public void run() {
|
||||
while (running) {
|
||||
synchronized (lock) {
|
||||
while (messages.isEmpty()) {
|
||||
waitNextMessage();
|
||||
if (!running) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
writeMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Set the running status.
|
||||
@ -166,11 +165,14 @@ public final class WritingRunnable implements Runnable {
|
||||
/** Wait for next message. */
|
||||
private void waitNextMessage() {
|
||||
try {
|
||||
synchronized (lock) {
|
||||
while (running && messages.isEmpty()) {
|
||||
lock.wait(TIMEOUT);
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
if (running) {
|
||||
LOGGER.log(Level.SEVERE,
|
||||
"Thread interruption exception.", e); //$NON-NLS-1$
|
||||
LOGGER.log(Level.SEVERE, "Thread interruption exception.", e); //$NON-NLS-1$
|
||||
}
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
@ -179,8 +181,7 @@ public final class WritingRunnable implements Runnable {
|
||||
/** Write next message to output. */
|
||||
private void writeMessage() {
|
||||
final String message = messages.poll();
|
||||
final ByteBuffer buff = charset
|
||||
.encode(message + System.lineSeparator());
|
||||
final ByteBuffer buff = charset.encode(message + System.lineSeparator());
|
||||
if (buff.hasArray()) {
|
||||
try {
|
||||
outPrint.write(buff.array());
|
||||
|
Loading…
Reference in New Issue
Block a user