Hope no-one minds, but I've also posted the following in the Apache/Tomcat forum. Not sure whether the problem is with the servlets or Tomcat, so I'm posting here as well...
The people that host my servlets have asked me the following question:
"When we restart Tomcat, for some reason the number of java processes starts off at about 20 but rises to over 100 over time? any idea why this is - I'm not too familiar with how java works to know if this is normal or not."
Is this normal behaviour?
They are hosting about 20 of my servlets and (as far as I know), no-one elses.
To help try and figure what might be going wrong, I have put the following code into one of my servlets:
As far as I'm aware, my servlets are ok - a couple of them do contain an inner class that extends Thread, but these are only instantiated once by each servlet in the init() method and they are daemon threads.
Also, it may be worth mentioning that about 4 of my servlets use contextlisteners, so maybe this has something to do with it.
Maybe nothing is wrong and all is normal, but I would appreciate any responses.
Why don't you try giving your daemon threads some sort of name so that you can figure out which ones are yours? Of course, the http-8084-Processor threads are Tomcat's.
James Carman, President<br />Carman Consulting, Inc.
Joined: Jan 22, 2004
Thanks for the reply. I've now followed your suggestion. I also included a timestamp in the thread's name which has also proved useful.
The situation is that tomcat is frequently restarted in order to pick up any changes to my servlets. Problem is though that my daemon threads are staying alive when Tomcat is restarted, so I am getting extra instances of these daemon threads for every Tomcat restart...
So it seems like I will have to kill the threads off myself in a context listener...
it should, but it seems as if it may not be? Of course a more likely cause is a problem in the threads themselves, maybe they're blocked waiting for some resource and thus can never terminate.
Joined: Feb 20, 2001
Originally posted by Ben Souther:
You shouldn't have to do that for daemon threads. The server should bring them down automatically.
This is probably why you're not supposed to start your own threads inside the servlet container (I'm guilty of it too, though). Daemon threads will stop upon JVM shutdown (of course), but restarting a webapp does not invoke an entirely new JVM. It just re-establishes a new servlet context using a brand new classloader.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com