Skip to content

Shut down the command line's thread pool when formatting is done - #47

Merged
abashev merged 1 commit into
mainfrom
close-thread-pool
Sep 23, 2026
Merged

abashev merged 1 commit into
mainfrom
close-thread-pool

Conversation

@abashev

@abashev abashev commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #40, split out of #45. Upstream report: google/google-java-format#384.

What changes

Main.formatFiles created 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 runs Main in-process kept up to MAX_THREADS idle threads per call.

The pool is now created in a try-with-resources. On Java 21 ExecutorService is AutoCloseable, and close() 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.formatLeavesNoPoolThreadRunning runs format from 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:test on JDK 21: 1448 tests, all green.

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
abashev disabled auto-merge September 23, 2026 10:32
@abashev
abashev merged commit 43df12f into main Sep 23, 2026
10 checks passed
@abashev
abashev deleted the close-thread-pool branch September 23, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant