I have a question about the threads that Tomcat uses for servicing requests.  
My environment is Tomcat 7.0.55 running on Linux (CentOS 6.5) with Oracle JVM 
1.7.0_79.

My question is specifically about the threads that Tomcat uses for servicing 
requests which are named ‘http-bio-{port}-exec-###’, as revealed by 
Thread.getName().  I have — for better or worse — written a servlet that caches 
some information using ThreadLocal[.set()][.get()]  for performance.  This 
mostly works very well, except that the number of threads in Tomcat’s Execution 
pool seem to change, with old threads going away, and new ones being created, 
and I have a need to know when any of these threads go away, so that I can 
perform some clean-up.

I am not asking about maxThreads, minThreads, etc., and I get how to configure 
the number of threads in the pool.  However, if I configure a particular pool 
size to say 50, I will see in the Tomcat Manager / Status page that the pool 
never goes above 50 (and current threads is usually much lower).  When the 
threads start out, they will begin as:

        http-bio-{port}-exec-1
        http-bio-{port}-exec-2
        http-bio-{port}-exec-3
        … etc …

However, if I leave the server running, they will eventually become:

        http-bio-{port}-exec-101
        http-bio-{port}-exec-102
        http-bio-{port}-exec-103
        … etc …

even though there are always less than 50 threads at any given time.

So my question is whether there is any way to tell when one of the threads is 
stopped (removed from the queue?) by Tomcat, and if I can hook any code to 
execute before it does?  My goal is to be able to tell when a thread is about 
to be killed so that I can do some clean-up.

Or is the answer dotn’s ThreadLocal for anything that needs clean-up, as there 
is no way to tell when Tomcat is going to stop (remove?) a thread from its 
queue?

Extra credit question: when does Tomcat decided to kill a thread, since 
although understand that would happen when the queue size expands and 
collapses, on my development server I doubt I’m ever going beyond minThreads.  
Does each thread only handle a fixed number of requests before it terminates, 
perhaps to prevent memory leaks?

I am hoping that this is the best place to ask this question.  I have tried 
searching the ‘Net, and couldn’t find anything, although I acknowledge that 
perhaps I am asking something that is just not possible.

Thanks in advance to anyone who can shed any light on this.  And I do know how 
to hook a servlet being shut down, which is not what I am asking.

Regards,

Dave.


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

Reply via email to