Re: Tomcat 10 and virtual thread

Christopher Schultz <[email protected]>
Newsgroups gmane.comp.jakarta.tomcat.user
Message-ID <[email protected]>
Francois,

On 11/3/25 11:04 AM, COURTAULT Francois wrote:
> Looking at https://tomcat.apache.org/tomcat-10.1-doc/config/executor.html we can configure Tomcat 10.1.x to use virtual threads
> instead of platform threads. Do you confirm ?
> 
> The way to do it, as far as I understood, is to:
> 
>    *   first, declare an executor in server.xml like below
> <Executor name="virtualThread"
>                                        className="org.apache.catalina.core.StandardVirtualThreadExecutor" />
> 
>    *   second, use a connector which will refer this above Executor thanks to its name attribute.
> The way I do it, is to update line 74, in server.xml, from <Connector port="8080" protocol="HTTP/1.1" to
>                                                                                                                           <Connector executor="virtualThread" port="8080" protocol="HTTP/1.1"
> 
> I started Tomcat and triggered a thread dump.
> I was not able to see any tomcat-virt string.
> Does it mean that the virtual thread usage is still disabled ?

I think there may be some confusion, here.

The Virtual Thread executor will create and discard threads very 
rapidly. It's possible that you will be unable to use jstack or another 
method to trigger a thread-dump where you can see any threads with names 
like "tomcat-virt-N" where N is some number.

Instead, try looking at a log file where the thread name is being 
displayed (e.g. fairly standard for an application log using log4j, 
JULI, etc.).

An alternative would be to trigger an exception to be thrown from your 
application, in which case you should be able to see the thread at the 
root of the exception stack trace like this:

    [....]
    at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:72)
    at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
    at 
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:398)
    at 
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
    at 
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:935)
    at 
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1831)
    at 
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
    at java.lang.VirtualThread.run(VirtualThread.java:466)

Note the final line of the stack trace coming from 
java.lang.VirtualThread.run().

You could also look for "catalina-exec-" in your thread dump to confirm 
none exist. If you were using the standard (non-virtual) executor, you 
should see some threads named catalina-exec in the JVM when you trigger 
a thread dump.

-chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.