Java Debugging

From Training Material
Jump to: navigation, search

Java Debugging
Sam Bashton

Java Debugging          Sam Bashton

Debugging Java applications ⌘

  • Debugging tools are more limited on RHEL5
  • Still many options

Showing JVM properties ⌘

 jinfo <java process id>

Showing heap usage ⌘

  • You can see the heap usage of an application with jmap
 jmap <java process id>

Showing object heap usage ⌘

 jmap -histo <java process id>
  • It may be necessary to 'force' on newer Java versions:
 jmap -F -histo <java process id>

Taking a thread dump ⌘

  • Shows more details on what an application is doing
  • Dumps thread output to stdout
 - If you started your Java process redirecting stdout to /dev/null,
   you're out of luck..
  • Take two thread dumps to show stuck threads
  pkill -3 java; sleep 5; pkill -3 java

Take a stack trace ⌘

  • `jstack <java process id>`
  • If the app uses JNI, take a mixed-mode trace:
 jstack -m <java process id>

Showing garbage collection details ⌘

  • Start the JVM with `-verbose:gc` to get details about garbage collection printed to stdout on each collection
 For even more verbosity, use `-XX:+PrintGCDetails

Disabling explicit garbage collection ⌘

  • Applications can manually invoke full garbage collection by calling `System.gc()`
  • This can be disabled by adding command line option
 -XX:+DisableExplicitGC` at JVM startup

Exercise ⌘

  • Try all of the mentioned techniques on your tomcat instance


  • jvisualvm