We have an application which leaks a bit of memory, a bit being an understatement.
I am using jvisualvm
to try and find what is causing the problem.
I see the thread count grow quite a bit on threads starting with the name: http-8080- example: http:8080-42
My first guess is that each of those threads is a request hit from the client, as each client request is handled in its own thread.
My my problem is that those threads have been running for long periods of time (Thus far 10mins).
My question is this:
Is my assumption correct? If so, why is it that the Threads run for such a long time? Surely it can't still be busy serving the clients request?
By default, Tomcat sets maxThreads to 200, which represents the maximum number of threads allowed to run at any given time. You can also specify values for the following parameters: minSpareThreads : the minimum number of threads that should be running at all times.
To find the status of the in-use threads, Tomcat provides the ThreadPool MBean. The attributes currentThreadsBusy, currentThreadCount and maxThreads provide information on the number of threads currently busy, currently in the thread pool and the maximum number of threads that can be created.
The original Tomcat implementation of the Coyote con- nector follows a pure multi-threaded approach to manage the client connections.
The default installation of Tomcat sets the maximum number of HTTP servicing threads at 200. Effectively, this means that the system can handle a maximum of 200 simultaneous HTTP requests.
Tomcat always has a number of waiting HTTP threads, for example if we look at the default connector setting:
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
We can see that there should always be at least 25 threads live, but waiting for connections (up to the maxThreads limit). This is controlled by the min and maxSpareThreads attributes.
What does JVisual VM state that the thread is doing waiting or locked on a resource etc etc?
Generally speaking, application servers will pre create a number of threads. Not only will the app server create them, but it will keep the threads around. This is known as a thread pool. The server will take a request and dispatch it to a thread, and when that request completes, the server will dispatch a new request to that thread.
Thread creation overhead is rather expensive so handling many requests benefits greatly from sharing threads. To answer your question, dispatching threads created by the server (assuming no serious runtime errors occur) will live for the lifetime of the server.
As for what you are seeing, if you see many many threads being started, then some other part of the application can be forking threads in which is a completely separate issue.
Its important to know that your tomcat server should not be creating new threads for each request (again generally speaking) it should reusing threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With