Dear Tomcat Users,
I hope this message finds you well.
As per your previous email, we attempted to fetch the virtual thread count from 
the keepAliveCount attribute in the Catalina.ThreadPool MBean.
For context, here is the setup we used:

  *   We created a sample Spring Boot application that continuously creates 
virtual threads in a loop.
  *   The application was deployed in the TOMCAT_LOCATION/webapps directory and 
started on localhost.
In Apache Tomcat 10.1.36, we added the following configuration to the 
server.xml file to enable virtual threads:
<Executor name="tomcatExecutor" 
className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
            connectionTimeout="18000" redirectPort="8443"
            executor="tomcatExecutor"
            useVirtualThreads="true"/>

Its observed in the logs that virtual threads were being created as expected. 
However, we noticed that the keepAliveCount attribute in the 
Catalina.ThreadPool MBean is showing a value of 0, even though virtual threads 
are being spawned.
It seems that the keepAliveCount attribute does not provide a valid value for 
counting the virtual threads. We were wondering if this is expected behavior, 
or if there is a different way to monitor the virtual threads created in Tomcat.
We would also like to know if there's a way to differentiate between platform 
threads and virtual threads using any MBean attribute in the Catalina service 
or elsewhere in Tomcat's MBean architecture.
We would greatly appreciate any guidance or insights you can provide regarding 
this issue.
Best Regards,
Rose Mary



From: Joash Jose <joash.j...@ibm.com>
Date: Wednesday, 26 March 2025 at 12:48 PM
To: Rose Mary P T <rose.mary...@ibm.com>
Subject: <no subject>



Begin forwarded message:

From: Mark Thomas <ma...@apache.org>
Subject: [EXTERNAL] Re: Monitoring Virtual Threads via JMX / MBeans in Tomcat
Date: 6 March 2025 at 2:08:43 PM IST
To: <users@tomcat.apache.org>
Reply-To: "Tomcat Users List" <users@tomcat.apache.org>

On 06/03/2025 06:29, Joash Jose wrote:

Dear Apache Tomcat Support Team,
I hope this message finds you well.
I am writing to inquire whether Apache Tomcat (tomacat version is 10.1.33 
running on Java 21)  exposes virtual thread metrics through JMX / MBeans. 
Specifically:
Virtual Thread Visibility:
Does Tomcat provide MBeans (e.g., under Catalina:type=Executor) to monitor 
virtual thread usage, such as active virtual thread counts, creation rate, or 
parking states?

No with a few caveats - see below).


If not, are there plans to add such metrics in future releases?

No.


Or any alternate ways with which we can monitor this from tomcat side.?

(connectionCount - keepAliveCount) should be a reasonable estimate of the 
virtual threads currently being used.

If the requests are synchronous (and there is little point using virtual 
threads with async requests) then the creation rate is derivable from the 
requestCount in the GlobalRequestProcessor.

There is no information on parking states.


Configuration Clarification:
We have configured Tomcat 10.1.33 with,
<Executor name="tomcatThreadPool" 
className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
<Connector port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol" 
connectionTimeout="18000" socket.soTimeout="18000" redirectPort="8443" 
enableLookups="false" URIEncoding="UTF-8" compression="on" 
useVirtualThreads="true" server="ARandomServer"/>

The <Executor .../> element isn't being used. Why configure it?


While this works, the existing ThreadPool MBeans show currentThreadsBusy=-1 and 
maxThreads=200 (incorrect in case of virtual threads). Is this expected 
behavior?

Yes.


JVM vs. Tomcat Metrics:
We observe that the JVM’s java.lang.management.ThreadMXBean includes virtual 
threads, but this aggregates data across all applications on the JVM. Does 
Tomcat offer a way to isolate virtual thread metrics specific to Tomcat?

No, because the JVM doesn't provide a mechanism to have multiple 
pools/groups/anything of virtual threads.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
Begin forwarded message:

From: Joash Jose <joash.j...@ibm.com>
Subject: Monitoring Virtual Threads via JMX / MBeans in Tomcat
Date: 6 March 2025 at 11:59:29 AM IST
To: <d...@tomcat.apache.org>, <users@tomcat.apache.org>

Dear Apache Tomcat Support Team,

I hope this message finds you well.

I am writing to inquire whether Apache Tomcat (tomacat version is 10.1.33 
running on Java 21)  exposes virtual thread metrics through JMX / MBeans. 
Specifically:

Virtual Thread Visibility:

Does Tomcat provide MBeans (e.g., under Catalina:type=Executor) to monitor 
virtual thread usage, such as active virtual thread counts, creation rate, or 
parking states?
If not, are there plans to add such metrics in future releases?
Or any alternate ways with which we can monitor this from tomcat side.?

Configuration Clarification:
We have configured Tomcat 10.1.33 with,
<Executor name="tomcatThreadPool" 
className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
<Connector port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol" 
connectionTimeout="18000" socket.soTimeout="18000" redirectPort="8443" 
enableLookups="false" URIEncoding="UTF-8" compression="on" 
useVirtualThreads="true" server="ARandomServer"/>
While this works, the existing ThreadPool MBeans show currentThreadsBusy=-1 and 
maxThreads=200 (incorrect in case of virtual threads). Is this expected 
behavior?

JVM vs. Tomcat Metrics:
We observe that the JVM’s java.lang.management.ThreadMXBean includes virtual 
threads, but this aggregates data across all applications on the JVM. Does 
Tomcat offer a way to isolate virtual thread metrics specific to Tomcat?

Regards,
Joash
Begin forwarded message:

From: Joash Jose <joash.j...@ibm.com.INVALID>
Subject: [EXTERNAL] Monitoring Virtual Threads via JMX / MBeans in Tomcat
Date: 6 March 2025 at 11:59:40 AM IST
To: "d...@tomcat.apache.org" <d...@tomcat.apache.org>, 
"users@tomcat.apache.org" <users@tomcat.apache.org>
Reply-To: "Tomcat Users List" <users@tomcat.apache.org>

Dear Apache Tomcat Support Team,

I hope this message finds you well.

I am writing to inquire whether Apache Tomcat (tomacat version is 10.1.33 
running on Java 21)  exposes virtual thread metrics through JMX / MBeans. 
Specifically:

Virtual Thread Visibility:

Does Tomcat provide MBeans (e.g., under Catalina:type=Executor) to monitor 
virtual thread usage, such as active virtual thread counts, creation rate, or 
parking states?
If not, are there plans to add such metrics in future releases?
Or any alternate ways with which we can monitor this from tomcat side.?

Configuration Clarification:
We have configured Tomcat 10.1.33 with,
<Executor name="tomcatThreadPool" 
className="org.apache.catalina.core.StandardVirtualThreadExecutor"/>
<Connector port="8080" protocol="org.apache.coyote.http11.Http11Nio2Protocol" 
connectionTimeout="18000" socket.soTimeout="18000" redirectPort="8443" 
enableLookups="false" URIEncoding="UTF-8" compression="on" 
useVirtualThreads="true" server="ARandomServer"/>
While this works, the existing ThreadPool MBeans show currentThreadsBusy=-1 and 
maxThreads=200 (incorrect in case of virtual threads). Is this expected 
behavior?

JVM vs. Tomcat Metrics:
We observe that the JVM’s java.lang.management.ThreadMXBean includes virtual 
threads, but this aggregates data across all applications on the JVM. Does 
Tomcat offer a way to isolate virtual thread metrics specific to Tomcat?

Regards,
Joash
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to