Skip to content

Commit

Permalink
Testing thread interruption.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
  • Loading branch information
spericas committed Nov 25, 2024
1 parent 7f9d8ac commit d755e24
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void write(BufferData buffer) {
asyncMode = false;
}
} else {
asyncWriter.drainQueue();
asyncWriter.drainQueueAndInterrupt();
writeNow(buffer); // blocking write
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SocketWriterAsync extends SocketWriter implements DataWriter {
private final AtomicBoolean started = new AtomicBoolean(false);
private volatile Throwable caught;
private volatile boolean run = true;
private Thread thread;
private volatile Thread thread;
private double avgQueueSize;

/**
Expand Down Expand Up @@ -142,14 +142,20 @@ private void checkRunning() {
executor.submit(this::run);
}
if (!run) {

throw new SocketWriterException(caught);
}
}

void drainQueue() {
BufferData buffer;
while ((buffer = writeQueue.poll()) != null) {
writeNow(buffer);
void drainQueueAndInterrupt() {
if (thread != null) {
thread.interrupt();
thread = null;

BufferData buffer;
while ((buffer = writeQueue.poll()) != null) {
writeNow(buffer);
}
}
}

Expand Down

0 comments on commit d755e24

Please sign in to comment.