Repository navigation
feat: Add optional Virtual Thread support to JettyComponent (#88) - #90
Conversation
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>
There was a problem hiding this comment.
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
virtualThreadsproperty toJettyComponentand pass it through to adapter options. - Update
JettyAdapterto use Jetty’sVirtualThreadPoolwhenvirtualThreads?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; |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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>
Summary
virtualThreadsboolean property toJettyComponent(default:true)true,JettyAdapteruses Jetty'sVirtualThreadPoolinstead ofQueuedThreadPooltruebecause the project requires Java 25 where Virtual Threads are fully supported and production-readyTest plan
JettyAdapterTesttests pass with default (virtual thread) modevirtualThreadPoolStartsAndHandlesRequesttest verifiesvtServer.getThreadPool()isVirtualThreadPooland server returns 200🤖 Generated with Claude Code