4

We are using new relic to monitor tomcat threads. The graph shows increase of thread count,but it never decreased even the application is idle. We noticed that when it increase CPU also increased and CPU got reduced when application is idle. But tomcat threads are not reduced. Is it expected or how to bring the thread count ?

1
  • I am also similar issue, the threads are not getting decreased. Can you please help on how you solved it? Jan 12, 2022 at 6:03

1 Answer 1

3

To answer your question, it depends on how you've configured Tomcat. It'll use a pool of threads to process your requests and that pool can shrink. See the minSpareThreads and maxIdleTime of the Executor object.

If you're not using an Executor and are relying on the default pool created by the connector you have less control. You can set minSpareThreads, but not maxIdleTime. If you're not using an executor, switching is easy. Just create one in your configuration (i.e. server.xml) and set the executor attribute on your connector. The default server.xml has an example, although it's commented out.

Beyond that, it's worth mentioning that other things in the JVM can be creating threads. I don't know specifically what you're monitoring, if it's all threads in the JVM or just the ones Tomcat is using to handle requests, but your applications and libraries used by those applications may be causing the problem. If you're seeing unbounded thread growth, you should take some thread dumps and see exactly what threads are being created. It may not be Tomcat that is creating these threads.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .