Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat threads != JVM threads?

The Tomcat Manager reports a different thread count than ThreadMXBean. The number of threads reported by ThreadMXBean is the same as the number of threads reported in the YourKit profiler as well. Is there a difference between Tomcat threads and JVM threads?

Line from Tomcat Manager:
Max threads: 200 Current thread count: 7 Current thread busy: 3

ManagementFactory.getThreadMXBean().getThreadCount():
38

like image 823
Keith Avatar asked Mar 09 '11 04:03

Keith


2 Answers

Tomcat thread are request processing threads, and does not count other thread that the application may have started.

For a better look on what those other thread are, take a look at Thread.getAllStackTraces().

like image 148
The Scrum Meister Avatar answered Sep 29 '22 22:09

The Scrum Meister


According to the javadocs, ManagementFactory.getThreadMXBean().getThreadCount():

Returns the current number of live threads including both daemon and non-daemon threads.

Therefore, the JVM could very well have 38 different threads going (mostly in the background). Tomcat makes a new thread for each request (so that it can have concurrent communication). It would make sense that these two numbers could differ.

like image 41
Chris Avatar answered Sep 29 '22 21:09

Chris