The Source for Java Technology Collaboration
User: Password:



Bhakti Mehta

Bhakti Mehta's Blog

Obtaining and analyzing thread dumps

Posted by bhaktimehta on May 25, 2007 at 01:09 PM | Comments (4)

Most of us run into bugs where tests "hang". Here are some nice tools and tips I found to obtain and analyze thread dumps. I am sure there may be other tools so if you know of some good ones feel free to add.

Jstack
jstack prints Java stack traces of Java threads for a given Java process or core file or a remote debug server. However jstack is not available for Windows platforms or on the Linux platform.

Stacktrace
Stacktrace has great features which include
1. Thread dump for Java processes running as a Windows service (like Tomcat, for example), started with javaw.exe or embedded inside another process.
2. Thread dump for any applet running inside any browser (Apple, IBM and Sun JDKs for Windows and Mac OS X). StackTrace is known to work with IE, Firefox, Safari and Mozilla.
and many other features..


I usually get the java process id using jps

Control Break/ kill  options

On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. For example, on Solaris you can use the command kill -QUIT process_id,
where process_id is the process number of your Java program.

Alternatively you can enter the key sequence <ctrl>\ in the window where the Java program was started. Sending this signal instructs a signal handler in the JVM, to recursively print out all the information on the threads
and monitors inside the JVM.
To generate a stack trace on Windows platforms, enter the key sequence <ctrl><break> in the window where the Java program is running, or click the Close button on the window.

Byron Nevins has also pointed in his blog how to obtain thread dumps in Glassfish.

TDA
This is a great utility I found for analyzing thread dumps.

I especially liked the ability to filter the threads display to be able to ignore e.g. idle threads.. Also as you can see in Fig 1 The three pane view is really helpful

tda.jpg Fig 1 : Using TDA to analyze thread dumps


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • jstack is available for Windows starting with JDK 6. For more info. see Alan's blog entry.

    Posted by: gsporar on May 28, 2007 at 05:02 PM

  • jstack works on Linux too -- except on Linux/IA-64. Also, as Gregg noted jstack is available on Windows starting with JDK 6.

    Posted by: sundararajana on May 31, 2007 at 12:08 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds