views:

1173

answers:

4

I've been running Tomcat 5.5 with Java 1.4 for a while now with a huge webapp. Most of the time it runs fine, but sometimes it will just hang, with no exception generated, and no apparant way of getting it to run again other than re-starting Tomcat. The tomcat instance is allowed a gigabyte of memory on the heap, but rarely exceeds 300 MB. Has anyone else run into this issue, and is there a solution for it?

For clarification: I determined how much memory it is using via Task Manager and via Eclipse (I've also tried running it outside of Eclipse, but get the same problem eventually, though it takes a little longer). With Eclipse, I look at the memory allocated via its little (optional) memory pane and the amount allocated to javaw.exe via the task manager. I use the sysdeo? tomcat plugin for Eclipse.

A: 

It sounds like you're hitting a deadlock.

If you can reproduce it in a dev environment then try attaching a debugger once it's happened. Take a look at your threads and see if you have any deadlocks.

If you can't get a debugger to attach you should be able to generate a thread dump, as Dustin pointed out.

Herms
+3  A: 

For any jvm process, force a thread dump. In windows, this can be done with CTRL-BREAK, I believe, in the console window.

In *nix, it is almost always "kill -3 jvm-pid".

This may show if you have threads waiting on db connection pool/thread pool, etc.

Another thing to check out is how many connections you have currently to the JVM -- either use NETSTAT or SysInternals utility such as tcpconn/tcpview (google it).

Also, try to run with the verbose:gc JVM flag. For Sun's JVM, run like "java -verbose:gc". This will show your garbage collections. If it is collecting a lot (FULL COLLECTIONS, expecially) then you probably have a memory leak. The full collections are costly, especially on large heaps like that.

How are you determining that only 300mb are being used?

Dustin
What happens if Tomcat is running as a service in Windows? There's no console window, so how would you get a thread dump?
Herms
Perhaps several options -- jstack (1.5 or 1.6 only, I think) or something like AdaptJ http://www.adaptj.com/main/. jstack is really cool to use.
Dustin
A: 

Try increasing the logging sensitivity for the Tomcat application server. http://tomcat.apache.org/tomcat-5.5-doc/logging.html

You can increase the sensitivity to FINEST or ALL for most of them for a few days and see if that helps you catch anything.

zxcv
A: 

I agree with creating multiple thread dumps and viewing them though this: Thread Dump Analyzer

Kevin