Use virtual threads by default on Java 21+ via Multi-Release JAR#60
Draft
Use virtual threads by default on Java 21+ via Multi-Release JAR#60
Conversation
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/e74714e4-bb84-4af7-b1ef-44f576c5b37c Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/e74714e4-bb84-4af7-b1ef-44f576c5b37c Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Use virtual threads by default on Java 21
Use virtual threads by default on Java 21+ via Multi-Release JAR
Apr 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a multi-release JAR approach to automatically use virtual threads on Java 21+ for the SDK’s internal I/O threading while keeping Java 17 as the baseline runtime.
Changes:
- Add a
ThreadFactoryProviderabstraction insrc/main/java/and a Java 21+ override insrc/main/java21/to switch internal threads to virtual threads via MR-JAR. - Update build configuration (manifest
Multi-Release: true, compilesrc/main/java21on JDK 21+ profile, Spotless includes). - Update internal thread creation call sites and refresh docs/examples to describe virtual thread behavior.
Show a summary per file
| File | Description |
|---|---|
pom.xml |
Enables MR-JAR manifest entry; compiles Java 21 sources under the JDK 21+ profile; expands Spotless includes to cover src/main/java21. |
src/main/java/com/github/copilot/sdk/ThreadFactoryProvider.java |
Baseline (Java 17) thread/executor factory implementation using platform daemon threads. |
src/main/java21/com/github/copilot/sdk/ThreadFactoryProvider.java |
Java 21+ MR-JAR overlay switching to virtual threads / virtual-thread executors. |
src/main/java/com/github/copilot/sdk/JsonRpcClient.java |
Routes JSON-RPC reader loop executor creation through ThreadFactoryProvider. |
src/main/java/com/github/copilot/sdk/CliServerManager.java |
Routes CLI stderr forwarding thread creation through ThreadFactoryProvider. |
src/test/java/com/github/copilot/sdk/ThreadFactoryProviderTest.java |
Adds unit tests for the provider. |
src/main/java/com/github/copilot/sdk/CopilotClient.java |
Javadoc update documenting Java 21+ virtual thread behavior and scheduler exception. |
src/main/java/com/github/copilot/sdk/CopilotSession.java |
Javadoc update clarifying scheduled timeout threads remain platform threads. |
README.md |
Updates requirements wording and adds a “Virtual Threads” section. |
src/site/markdown/index.md |
Recommends Java 21+ for automatic virtual thread support. |
src/site/markdown/getting-started.md |
Recommends Java 21+ for automatic virtual thread support. |
src/site/markdown/advanced.md |
Adds an advanced “Virtual Threads (Java 21+)” section. |
jbang-example.java |
Notes automatic virtual thread usage on Java 21+. |
Copilot's findings
- Files reviewed: 13/13 changed files
- Comments generated: 6
src/test/java/com/github/copilot/sdk/ThreadFactoryProviderTest.java
Outdated
Show resolved
Hide resolved
Comment on lines
+21
to
+26
| final class ThreadFactoryProvider { | ||
|
|
||
| private static final Logger LOG = Logger.getLogger(ThreadFactoryProvider.class.getName()); | ||
|
|
||
| private ThreadFactoryProvider() { | ||
| } |
There was a problem hiding this comment.
LOG is declared but never used in this class. Please remove it (and any now-unneeded logging import) to avoid dead code and future confusion.
Contributor
Author
There was a problem hiding this comment.
Already addressed in commit 9d456f6 — the unused LOG field and java.util.logging.Logger import were removed from both the baseline and Java 21 overlay ThreadFactoryProvider files.
src/main/java21/com/github/copilot/sdk/ThreadFactoryProvider.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
….java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rlay, fix empty docs section Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/46706dd3-402c-41c9-9150-3cfae7db8c3f Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
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.
Resolves #98
Before the change?
new Thread()andExecutors.newSingleThreadExecutor()calls, regardless of JVM version.After the change?
Core abstraction:
ThreadFactoryProviderinsrc/main/java/— baseline returning platform threadsThreadFactoryProviderinsrc/main/java21/— overlay usingThread.ofVirtual().name(...)withExecutors.newSingleThreadExecutor()backed by a virtual-thread factoryCall sites updated:
JsonRpcClient— reader executor now viaThreadFactoryProvider.newSingleThreadExecutor("jsonrpc-reader")CliServerManager— stderr thread now viaThreadFactoryProvider.newThread(..., "cli-stderr-reader")CopilotSessionScheduledThreadPoolExecutor— unchanged (no virtual-thread scheduled executor in JDK)Build:
Multi-Release: truemanifest entrymaven-compiler-pluginexecution with--release 21+multiReleaseOutput=truesrc/main/java21/**/*.javaCode review fixes:
LOGfield andjava.util.logging.Loggerimport from bothThreadFactoryProviderclassesExecutors.newSingleThreadExecutor(Thread.ofVirtual().name(name).factory())instead ofnewThreadPerTaskExecutor(...)to provide a true single-thread executor matching the method contractadvanced.mdwith actionable guidance (usingjcmdthread dumps and IDE thread inspectors)Docs: README, site docs (index, getting-started, advanced), jbang example, Javadoc on
CopilotClient/CopilotSession.Pull request checklist
mvn spotless:applyhas been run to format the codemvn clean verifypasses locallyDoes this introduce a breaking change?