8000 feat: Add optional Virtual Thread support to JettyComponent (#88) by kawasima · Pull Request #90 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content

feat: Add optional Virtual Thread support to JettyComponent (#88) - #90

Merged
kawasima merged 3 commits into
developfrom
feature/virtual-thread-jetty
Mar 14, 2026
Merged

kawasima merged 3 commits into
developfrom
feature/virtual-thread-jetty

Conversation

@kawasima
@kawasima kawasima commented Mar 14, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

  • Add virtualThreads boolean property to JettyComponent (default: true)
  • When true, JettyAdapter uses Jetty's VirtualThreadPool instead of QueuedThreadPool
  • No application code changes required to benefit from virtual threads
  • Default is true because the project requires Java 25 where Virtual Threads are fully supported and production-ready
  • Undertow excluded: XNIO does not officially support Virtual Threads (deferred to future issue)

Test plan

  • All existing JettyAdapterTest tests pass with default (virtual thread) mode
  • New virtualThreadPoolStartsAndHandlesRequest test verifies vtServer.getThreadPool() is VirtualThreadPool and server returns 200

🤖 Generated with Claude Code

kawasima and others added 2 commits March 14, 2026 09:51
Add a `virtualThreads` flag (default false) to JettyComponent.
When enabled, JettyAdapter uses Jetty's VirtualThreadPool instead of
QueuedThreadPool, allowing request handling on virtual threads with no
application code changes.

Undertow is excluded: XNIO does not officially support Virtual Threads;
support is deferred until Undertow ships a VT-safe integration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Since the project requires Java 25, Virtual Threads are always available.
Default to true so users get VirtualThreadPool out of the box without
explicit configuration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kawasima
kawasima requested a review from Copilot March 14, 2026 00:52
Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds opt-in support for running the Jetty server on virtual threads by wiring a new virtualThreads flag from JettyComponent into JettyAdapter, which can switch Jetty’s thread pool implementation.

Changes:

  • Add virtualThreads property to JettyComponent and pass it through to adapter options.
  • Update JettyAdapter to use Jetty’s VirtualThreadPool when virtualThreads? is enabled.
  • Add a new test intended to cover virtual-thread mode startup and request handling.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
enkan-component-jetty/src/main/java/enkan/component/jetty/JettyComponent.java Introduces virtualThreads property and forwards it into the adapter OptionMap.
enkan-component-jetty/src/main/java/enkan/adapter/JettyAdapter.java Adds VirtualThreadPool selection based on the virtualThreads? option.
enkan-component-jetty/src/test/java/enkan/adapter/JettyAdapterTest.java Adds a new test covering request handling with virtualThreads? enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

public class JettyComponent extends WebServerComponent<JettyComponent> implements HealthCheckable {
private Server server;
private BiFunction<Server, OptionMap, Connector> serverConnectorFactory;
private boolean virtualThreads = true;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The project requires Java 25 (set in the parent pom.xml as <java.version>25</java.version>), so Virtual Threads are always available and production-ready. Defaulting to true ensures users get VirtualThreadPool out of the box without explicit configuration. The PR description has been updated to reflect this intent.

Comment on lines +250 to +252
OptionMap options = OptionMap.of("http?", true, "port", vtPort, "host", "127.0.0.1",
"join?", fal 8000 se, "virtualThreads?", true);
Server vtServer = new JettyAdapter().runJetty(app, options);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Added assertThat(vtServer.getThreadPool()).isInstanceOf(VirtualThreadPool.class) before the HTTP request, which directly verifies that the VirtualThreadPool is selected when virtualThreads? is true.

Add an assertion on vtServer.getThreadPool() to verify that VirtualThreadPool
is selected when virtualThreads? is true, not just that the server responds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kawasima
kawasima merged commit 41f37be into develop Mar 14, 2026
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.

2 participants

0