File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed
Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,13 @@ protected void executeIt() throws Exception {
4141 delegate .println (line );
4242 }
4343 } catch (InterruptedException e ) {
44+ // We've been interrupted, which is the signal to shut down.
45+ // But before we exit, let's process any remaining messages in the queue.
46+ Object line ;
47+ while ((line = queue .poll ()) != null ) {
48+ delegate .println (line );
49+ }
50+ // Re-set the interrupt flag to be a good citizen.
4451 Thread .currentThread ().interrupt ();
4552 }
4653 }
Original file line number Diff line number Diff line change @@ -122,6 +122,11 @@ public Set<UUID> list() {
122122
123123 @ Override
124124 public void close () {
125+ // Signal to all running tasks, so they can terminate gracefully & fast
126+ for (Task <?, ?> task : tasks .values ()) {
127+ task .cancel ();
128+ }
129+
125130 TaskExecutorServices .close (executor );
126131 TaskExecutorServices .close (timeoutScheduler );
127132 }
Original file line number Diff line number Diff line change @@ -48,8 +48,6 @@ static void close(ExecutorService executor) {
4848 var start = System .currentTimeMillis ();
4949 logger .fine (() -> "Starting to shut down ExecutorService " + executor );
5050
51- // TODO Signal close() to all running tasks, so they can terminate gracefully & fast
52-
5351 // TODO Then (only) use Java 19+ executor.close()
5452
5553 executor .shutdown ();
You can’t perform that action at this time.
0 commit comments