Friday, October 3, 2008

[Tomcat] How to troubleshoot/find deadlocks or hanging threads in tomcat.

Sometimes you have threads hanging, or even worse, Deadlocks in your applications installed in Tomcat.

In those, and many other cases you can use the unix command "kill -3 " to signal to Tomcat that it should dump all the threads that it is currently working with into "tomcat/logs/catalina.out".
You can usually find tomcats processId by running "ps -ef | grep tomcat":

Example output from "ps -ef | grep tomcat":
jam 6721 6560 0 08:55 ? 00:00:51 /usr/java/jdk/bin/java -Dcatalina.home=...

The column marked in bold is the processId.

The clever thing about "kill -3" is that it doesn't actually shut tomcat down, it just signals tomcat to dump its threads so you can run this command in a live production environment.

After dumping the threads, you can analyse which processes are in the state "WAIT" and contains you class name in the thread dump. If you can find any of these, that's a good place to start looking for problems!

Enjoy!

No comments: