Tool for debugging hangs in java application

James T picture James T · Mar 23, 2012 · Viewed 18.2k times · Source

I've got a java application that half the time just hangs, and the other half the JVM crashes. Is there a tool I can use to see what's going on that makes it hang and/or crash? I'm using CentOS 5.6

Answer

ulmangt picture ulmangt · Mar 23, 2012

For starters I would suggest JVisualVM. It comes with the JDK, so you should just need to type jvisualvm into the command line to start it.

Once it starts, you can connect to a running JVM, so you should be able to connect to your hung Java process and inspect the stack dump for all its running threads as well as the contents of the heap.


Other useful built-in tools include:

jps lists process ids of running java processes

jstack prints a stack dump for each thread in the specified JVM process

jmap generates a heap dump for the specified JVM process (jvisualvm can also generate heap dumps)

jhat analyzes heap dumps generated with jmap or jvisualvm


Of couse, there are also more sophisticated profilers available. JProfiler is quite highly regarded.