The default HttpServer Executor

Daniel Fuchs daniel.fuchs at oracle.com
Tue May 13 18:28:26 UTC 2025


Hi Josiah,

The HttpServer doesn't use any default
executor - it has one dispatcher thread and by default
serves requests serially from the dispatcher thread.
For backward compatibility I don't think we will ever
change that default behaviour.

An executor can however be supplied to the HttpServer
using `HttpServer.setExecutor` [1]

The HttpServer mostly uses monitors for synchronization.
With JEP 491 delivered [2], using Virtual Threads with
the HttpServer has become more friendly, and anyone wishing
to use VirtualThread with their HttpServer instance
can therefore pass a VirtualThreadPerTaskExecutor to
their instance.

Their might still be some side effect with using
virtual thread however, especially if invoking code
calling a native method that blocks, or loading a class
that blocks in its static initializers.

So using VirtualThread should be a conscious choice
from the application designers.

If you are speaking of `jwebserver` - then we deliberately
choose to not use any executor there, and I don't think we
would change that.

best regards,

-- daniel

[1] 
https://docs.oracle.com/en/java/javase/24/docs/api/jdk.httpserver/com/sun/net/httpserver/HttpServer.html#setExecutor(java.util.concurrent.Executor)
[1] https://openjdk.org/jeps/491

On 13/05/2025 18:17, Josiah Noel wrote:
> Hey Team,
> 
> Has there been any discussion about changing the default executor of the 
> JDK HTTP server implementation to use virtual threads?
> 



More information about the net-dev mailing list