Skip to content

Allow stopping thread pools manually#15312

Draft
svalaskevicius wants to merge 6 commits intoapache:mainfrom
svalaskevicius:control-of-static-thread-pools
Draft

Allow stopping thread pools manually#15312
svalaskevicius wants to merge 6 commits intoapache:mainfrom
svalaskevicius:control-of-static-thread-pools

Conversation

@svalaskevicius
Copy link

  • 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)

 - 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)
@svalaskevicius svalaskevicius force-pushed the control-of-static-thread-pools branch from cbb17a3 to db22fba Compare February 13, 2026 10:44
Comment on lines 183 to 188
while ((item = invoked.poll()) != null) {
try {
item.awaitTermination(SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {
// We're shutting down anyway, so just ignore.
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is exactly what is being done :) the shutdown is invoked just above, this loop just waits for their completion

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! I see what you mean. ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be synchronized to work in a multi-threaded environment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@github-actions github-actions bot added the AWS label Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants