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 Tomcat and the fly likes Tomcat using too many processes? 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 » Products » Tomcat
Bookmark "Tomcat using too many processes?" Watch "Tomcat using too many processes?" New topic
Author

Tomcat using too many processes?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
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:



... which gives the following output:


There are 76 threads...

Thread0: Thread[main,5,main]. isAlive: true. isDaemon: false. isInterrupted: false

Thread1: Thread[Thread-2,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread2: Thread[ContainerBackgroundProcessor[StandardEngine[Catalina]],5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread3: Thread[http-8084-Processor1,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread4: Thread[http-8084-Processor2,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread5: Thread[http-8084-Processor3,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread6: Thread[http-8084-Processor4,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread7: Thread[http-8084-Processor5,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread8: Thread[http-8084-Processor6,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread9: Thread[http-8084-Processor7,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread10: Thread[http-8084-Processor8,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread11: Thread[http-8084-Processor9,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread12: Thread[http-8084-Processor10,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread13: Thread[http-8084-Processor11,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread14: Thread[http-8084-Processor12,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread15: Thread[http-8084-Processor13,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread16: Thread[http-8084-Processor14,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread17: Thread[http-8084-Processor15,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread18: Thread[http-8084-Processor16,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread19: Thread[http-8084-Processor17,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread20: Thread[http-8084-Processor18,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread21: Thread[http-8084-Processor19,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread22: Thread[http-8084-Processor20,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread23: Thread[http-8084-Processor21,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread24: Thread[http-8084-Processor22,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread25: Thread[http-8084-Processor23,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread26: Thread[http-8084-Processor24,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread27: Thread[http-8084-Processor25,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread28: Thread[http-8084-Monitor,5,main]. isAlive: true. isDaemon: false. isInterrupted: false

Thread29: Thread[TP-Processor1,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread30: Thread[TP-Processor2,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread31: Thread[TP-Processor3,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread32: Thread[TP-Processor4,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread33: Thread[TP-Monitor,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread34: Thread[http-8084-Processor26,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread35: Thread[http-8084-Processor27,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread36: Thread[http-8084-Processor28,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread37: Thread[http-8084-Processor29,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread38: Thread[http-8084-Processor30,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread39: Thread[http-8084-Processor31,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread40: Thread[http-8084-Processor32,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread41: Thread[http-8084-Processor33,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread42: Thread[http-8084-Processor34,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread43: Thread[http-8084-Processor35,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread44: Thread[http-8084-Processor36,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread45: Thread[http-8084-Processor37,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread46: Thread[http-8084-Processor38,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread47: Thread[http-8084-Processor39,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread48: Thread[http-8084-Processor40,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread49: Thread[http-8084-Processor41,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread50: Thread[http-8084-Processor42,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread51: Thread[http-8084-Processor43,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread52: Thread[http-8084-Processor44,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread53: Thread[http-8084-Processor45,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread54: Thread[http-8084-Processor46,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread55: Thread[http-8084-Processor47,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread56: Thread[http-8084-Processor48,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread57: Thread[http-8084-Processor49,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread58: Thread[http-8084-Processor50,5,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread59: Thread[Thread-61,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread60: Thread[Thread-62,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread61: Thread[Thread-64,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread62: Thread[Thread-65,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread63: Thread[Thread-67,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread64: Thread[Thread-69,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread65: Thread[Thread-72,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread66: Thread[Thread-73,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread67: Thread[Thread-76,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread68: Thread[Thread-77,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread69: Thread[Thread-78,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread70: Thread[Thread-80,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread71: Thread[Thread-90,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread72: Thread[Thread-91,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread73: Thread[Thread-92,1,main]. isAlive: true. isDaemon: true. isInterrupted: false

Thread 74 no longer exists

Thread 75 no longer exists


I wasn't expecting so many threads either!...

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.

Many thanks,
James
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I know when I run Tomcat in eclipse it kicks off around 50 threads or more. I'm not sure why though.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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.


42
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Guys,

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...

Thanks again,
James
Jayesh Lalwani
Ranch Hand

Joined: Nov 05, 2004
Posts: 502
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.

Oh, BTW, this happens in Windows environment
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat using too many processes?
 
Similar Threads
Aboutt Daemon Threads
Synchronization practice: why does thread1 rush through loop without pause or reset?
priority of garbage collector thread
Too many threads?
main thread