This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes counting running threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "counting running threads" Watch "counting running threads" New topic

counting running threads

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Sorry if it's not the right forum.

My question is, how do I count the number of running threads in server?

Some thoughts: Whenever a request comes from a browser (client), server creates a thread (or take one thread from thread pool?) & that thread executes (takes care of) that request, once response sent, thread gets over (or goes back in thread pool?).

Now if I increase a counter whenever a new thread is created by server (say in the beginning of service() method, though thread is already created by this time & thread itself is executing this service() method) and decrease it when response is sent to browser (in the very end of service() method), will this give me right number?

Any listener I can make use of? Or anything OOB available?

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
The Tomcat Management app can show you all of the request processing Thread in the Thread pool with their current state.

Since that is so useful I would expect similar tools for other servers.

Alternately you could create a request filter or create a modified service method.


jQuery in Action, 2nd edition
subject: counting running threads
Similar Threads
How does Apache Tomcat server handle the HTTPrequests?
How to use Threads in Servlets?
Threads for a servlet
allocating a thread to a servlet request
Socket reuse and security