Tool for debugging hangs in java application
Asked Answered
D

3

18

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

Duhamel answered 23/3, 2012 at 2:46 Comment(0)
G
18

There are two different cases.

Application crash: Was that an OOM? NPE? What was the exception? If there was jvm crash you will see hs_err_.log (http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf)

Looking at the file you may see if your own JNI caused a crash or JVM bug.

Application Hang: I would start with visualvm or jstat (both are part of JDK). You can see current state of threads and check if there is any application error..

Other linux tools that could help to see inside process:

  • lsof : you can check if the process opened too many files
  • strace: see current activity from system call point of view.

Oracle tools documentation provides pretty neat listing. It also links Operating System Specific tools

Gerianne answered 23/3, 2012 at 5:54 Comment(2)
@Bubby4j: Were you able to find out the crash reason? Was that any thing to do with os? I am going to evaluate centos for deploying our tool, a java based one.Gerianne
It was a problem with openvz.Duhamel
F
23

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.

Francinafrancine answered 23/3, 2012 at 2:56 Comment(0)
G
18

There are two different cases.

Application crash: Was that an OOM? NPE? What was the exception? If there was jvm crash you will see hs_err_.log (http://java.sun.com/j2se/1.5/pdf/jdk50_ts_guide.pdf)

Looking at the file you may see if your own JNI caused a crash or JVM bug.

Application Hang: I would start with visualvm or jstat (both are part of JDK). You can see current state of threads and check if there is any application error..

Other linux tools that could help to see inside process:

  • lsof : you can check if the process opened too many files
  • strace: see current activity from system call point of view.

Oracle tools documentation provides pretty neat listing. It also links Operating System Specific tools

Gerianne answered 23/3, 2012 at 5:54 Comment(2)
@Bubby4j: Were you able to find out the crash reason? Was that any thing to do with os? I am going to evaluate centos for deploying our tool, a java based one.Gerianne
It was a problem with openvz.Duhamel
F
2

In these cases(hang, freeze, ...) you have to analyze an heap dump to try to figure out what's happening in your application , you can use JVisualVM to take the dump, or you can add the appropriate JVM parameter to dump the content of the heap in the case of a crash.

Frontage answered 23/3, 2012 at 6:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.