Shut down the command line's thread pool when formatting is done - #47
Merged
Merged
Conversation
Main.formatFiles created a fixed thread pool on every call and never shut it down. The command line does not notice, because the process exits, but a tool that runs Main in-process kept up to MAX_THREADS idle threads per call (#40, from google/google-java-format#384). The pool is now closed when formatFiles returns. On Java 21 ExecutorService is AutoCloseable, and close() waits for the submitted tasks, which formatFiles has already waited for by then. The new MainTest runs format from a thread of its own thread group, which the pool's threads join, and fails without the change because a pool thread is still running.
abashev
force-pushed
the
close-thread-pool
branch
from
September 23, 2026 08:52
9d2df7f to
c10548d
Compare
abashev
disabled auto-merge
September 23, 2026 10:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #40, split out of #45. Upstream report: google/google-java-format#384.
What changes
Main.formatFilescreated a fixed thread pool on every call and never shut it down. The command line did not notice, because the process exits, but a tool that runsMainin-process kept up toMAX_THREADSidle threads per call.The pool is now created in a try-with-resources. On Java 21
ExecutorServiceisAutoCloseable, andclose()waits for the submitted tasks, which have all been waited for by then. The old body moved unchanged into an overload that takes the pool, so it is not re-indented in the diff.Checked
MainTest.formatLeavesNoPoolThreadRunningrunsformatfrom a thread in a thread group of its own; the pool's threads join that group. Without the change it fails with "pool-1-thread-1 is still running"../gradlew :open-java-format:teston JDK 21: 1448 tests, all green.