Allow stopping thread pools manually#15312
Allow stopping thread pools manually#15312svalaskevicius wants to merge 6 commits intoapache:mainfrom
Conversation
svalaskevicius
commented
Feb 13, 2026
- allows to stop thread pools manually, to avoid leaks in hot-reload environments
- allows to opt-out of the standard shutdown mechanism to manage graceful service stops (and commit the last pending files)
7f955d4 to
cbb17a3
Compare
- allows to stop thread pools manually, to avoid leaks in hot-reload environments - allows to opt-out of the standard shutdown mechanism to manage graceful service stops (and commit the last pending files)
cbb17a3 to
db22fba
Compare
| while ((item = invoked.poll()) != null) { | ||
| try { | ||
| item.awaitTermination(SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
| } catch (InterruptedException ignored) { | ||
| // We're shutting down anyway, so just ignore. | ||
| } |
There was a problem hiding this comment.
I think we want to do that in a concurrent fashion. Waiting one by one would mean waiting for N * SHUTDOWN_TIMEOUT_SECONDS seconds of time. Probably we need to collect a list of futures and wait on their completion for max SHUTDOWN_TIMEOUT_SECONDS.
There was a problem hiding this comment.
this is exactly what is being done :) the shutdown is invoked just above, this loop just waits for their completion
There was a problem hiding this comment.
ah! I see what you mean. ok
There was a problem hiding this comment.
I've started going about this with CompletableFuture but it needs it's own ExecutorService and grew in complexity...
instead, I opted for a simpler implementation to ensure the same - please have a look (just checking how much wait time can subsequent calls have)
| * Force manual shutdown of the thread pools created via the {@link #newExitingWorkerPool(String, | ||
| * int)}. | ||
| */ | ||
| public static void shutDownStartedThreadPools() { |
There was a problem hiding this comment.
I think this needs to be synchronized to work in a multi-threaded environment.
There was a problem hiding this comment.
the idea is that it uses ConcurrentLinkedDeque to safely drain the threadpools and shut them down, so should be safe to be called concurrently?
happy to add synchronized if you still think it is needed?