Skip to content

Commit 68994fb

Browse files
committed
clean: Remove useless TaskExecutorServices.close(Executor)
1 parent 13a4be1 commit 68994fb

File tree

3 files changed

+2
-37
lines changed

3 files changed

+2
-37
lines changed

src/dev/enola/be/io/NonBlockingLineWriter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
public class NonBlockingLineWriter extends TaskWithoutInputOutput implements LineWriter {
1111

12-
// TODO close() method to flush remaining messages? How would TaskExecutor know when to call it?
13-
1412
private final LineWriter delegate;
1513
private final BlockingQueue<Object> queue;
1614
private boolean overflow;

src/dev/enola/be/task/TaskExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void close() {
127127
task.cancel();
128128
}
129129

130-
TaskExecutorServices.close(executor);
131-
TaskExecutorServices.close(timeoutScheduler);
130+
executor.close();
131+
timeoutScheduler.close();
132132
}
133133
}
Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package dev.enola.be.task;
22

3-
import static java.util.concurrent.TimeUnit.SECONDS;
4-
5-
import java.time.Duration;
63
import java.util.concurrent.ExecutorService;
74
import java.util.concurrent.Executors;
85
import java.util.concurrent.ThreadFactory;
@@ -42,35 +39,5 @@ static ExecutorService newVirtualThreadPerTaskExecutor() {
4239
return Executors.newThreadPerTaskExecutor(factory);
4340
}
4441

45-
private static final long CLOSE_EXECUTOR_SHUTDOWN_AWAIT_SECONDS = 7;
46-
47-
static void close(ExecutorService executor) {
48-
var start = System.currentTimeMillis();
49-
logger.fine(() -> "Starting to shut down ExecutorService " + executor);
50-
51-
// TODO Then (only) use Java 19+ executor.close()
52-
53-
executor.shutdown();
54-
try {
55-
// Wait for existing tasks to terminate
56-
if (!executor.awaitTermination(CLOSE_EXECUTOR_SHUTDOWN_AWAIT_SECONDS, SECONDS)) {
57-
58-
// Cancel currently executing tasks
59-
executor.shutdownNow();
60-
}
61-
62-
} catch (InterruptedException ie) {
63-
// (Re-)Cancel if current thread also interrupted
64-
executor.shutdownNow();
65-
66-
// Preserve interrupt status
67-
Thread.currentThread().interrupt();
68-
}
69-
70-
var end = System.currentTimeMillis();
71-
var duration = Duration.ofMillis(end - start);
72-
logger.info(() -> "Finished shutting down ExecutorService " + executor + " in " + duration);
73-
}
74-
7542
private TaskExecutorServices() {}
7643
}

0 commit comments

Comments
 (0)