Java 1.6: Easier Thread Dumps For All
Thread dumps are an invaluable form of debugging, especially something running at a remote site. When you have no idea what is going on inside your application, a thread dump can be a life saver. However, depending on the operating system and method of launching the application, it can be difficult to get a thread dump by the traditional method (SIGQUIT on Unix and Control+Break in the console on Windows). Either it is difficult to find the right Java process (pre-NPTL Linux), it is difficult to find where stdout is going (when running as a service) or it is impossible to hit Control-Break (no console!).
Well, a couple of tools that first arrived in Unix 1.5 JDKs solve this problem. And now, in Java 1.6, they are available on Windows too. Those tools are jps (a ps for Java processes) and jstack (a tool to dump the threads of a specified Java process). Shipped with the JDK, these tools make getting a thread dump child’s play:
8328 com.zutubi.pulse.command.PulseCtl
5310 org.tanukisoftware.wrapper.WrapperStartStopApp
4306 org.apache.tools.ant.launch.Launcher
8729 sun.tools.jps.Jps
8350 org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner
jsankey@pal:~$
There you have the PIDs for all Java processes running as the current user, with the name of the main class. To dump the threads, pass the PID to jstack:
Attaching to process ID 8328, please wait…
Debugger attached successfully.
Client compiler detected.
JVM version is 1.5.0_08-b03
Thread 8581: (state = BLOCKED)
– sun.misc.Unsafe.park(boolean, long) @bci=0 (Interpreted frame)
…
Voila! Of course, if you have a graphical environment available, you can get all the goodness of jconsole too.
This entry was posted on Tuesday, February 13th, 2007 at 1:02 am and is filed under Java, Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.









