When 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.
That's just the Unix JVM (or some of them at least). It creates a process for every thread it creates. On Windows you get only 1 process and the JVM uses real threading.
On our test server Tomcat currently uses almost 70 processes and is just purring along nicely.
Joined: Jan 22, 2004
Thanks for the replies.
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...
I have seen Tomcat start multipe java processes in ur development environment too (and we don't even load the server ith too many requests on the development server). I don't totally understand why so many processes run at the same time. I initially thought that Tomcat starts a process for each webapp, but that's not true. Sometimes, there is one process for 2 webapps, and sometimes 2 processes for 1 webapp.
In one of the projects, we had a problem that Tomcat wouldn't stop when you stopped it. It would say Tomcat is stopped, and it would release the port and everything, but the processes would stay in memory. I nosed around in the logs a little bit, and saw that Tomcat was logging an exception because Serialization failed. Apparently, someone had put a non-serializable class in the session, and Tomcat would try to serialize the session when it shuts down. So, I think the shutdown would abort because of the exception. Meanwhile, developers would simply kill Tomcat, which sometimes resulted in some of the extra processes staying in memory.
So, the problem could be that they are killing the Tomcat process instead of shutting it down. This might result in old instances of Tomcat staying in memory using up resources.