-
Notifications
You must be signed in to change notification settings - Fork 982
HTTPCLIENT-2394: Virtual threads support for classic client #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPCLIENT-2394: Virtual threads support for classic client #717
Conversation
Add VirtualThreadCloseableHttpClient and builder options to run I/O (and optionally handler) on JDK 21 virtual threads. Default behavior unchanged; classic path used when VT unavailable. Include VirtualThreadSupport utility and example.
567f83d
to
3c54bd2
Compare
I don't understand this at all. What problem does this solve, compared to simply calling the client from a virtual thread? |
Virtual threads let blocking HttpClient scale: thousands of concurrent requests without bloated platform threads. |
In your example code, when you call:
You are blocking a platform thread, which waits for the request to execute on a virtual thread. I don't see how you can realize increased concurrency in this way; it's still a thread-per-request model, and you might as well just call into the client directly from the OS thread. The whole advantage of virtual threads over async/await is that virtual threads don't introduce function coloring. They are largely transparent to libraries. They allow everyone to write blocking, imperative code and scale up the concurrency by simply using a virtual thread factory instead of a conventional thread factory. And since HttpComponents is a pure Java library, we don't have to worry about pinning the carrier thread through blocking JNI calls or anything; Java already fixed that problem for us with JEP 353, and more recently JEP 491 made |
It’s a small, optional convenience—not a scalability silver bullet.
It’s a small, optional convenience—not a scalability silver bullet. |
@arturobernalg Likewise, I do not really understand the benefits of this change especially for the classic transport where the users are expected to manage the threads anyway. I am not in favor of this change. |
Introduce
VirtualThreadCloseableHttpClient
to run classic transport on JDK 21 virtual threads while preservingCloseableHttpClient
semantics and threading contract. Extend builder withuseVirtualThreads()
,virtualThreadNamePrefix()
,virtualThreadExecutor(...)
,virtualThreadShutdownWait(...)
, andvirtualThreadsRunHandler()
to control execution. AddVirtualThreadSupport
utility for JDK detection and per-task executor; include example and tests. Behavior remains unchanged unless enabled via the builder.