|
1 | 1 | package dev.enola.be.task; |
2 | 2 |
|
3 | | -import static java.util.concurrent.TimeUnit.SECONDS; |
4 | | - |
5 | | -import java.time.Duration; |
6 | 3 | import java.util.concurrent.ExecutorService; |
7 | 4 | import java.util.concurrent.Executors; |
8 | 5 | import java.util.concurrent.ThreadFactory; |
@@ -42,35 +39,5 @@ static ExecutorService newVirtualThreadPerTaskExecutor() { |
42 | 39 | return Executors.newThreadPerTaskExecutor(factory); |
43 | 40 | } |
44 | 41 |
|
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 | | - |
75 | 42 | private TaskExecutorServices() {} |
76 | 43 | } |
0 commit comments