By octav on Nov 14, 2007
The old proverb: "a picture is worth a thousand words", has an interesting mapping in the world of programming. On the Java platform one has a few facilities that enable a developer to get a stack trace that can point to the cause of a UI freeze, slow down in an application performance, etc. A thread dump can save a developer a lot of time in troubleshooting tough problems. In the old days one could start the application and a terminal and call CTRL + Break on the Windows platform or kill -QUIT pid on the Unix platform. Of course if one has access to the sources you can force the application to show you the call stack by doing something "un-natural" such as Thread.getCurrentThread().dumpStack(). Keep in mind that this will crash you application, so don't do it on production code. This wiki entry has more details on how to, gently , get a Thread dump.
In a recent conversation with Tor I learned some more details. For instance, on the Windows platform, using Java 6 one could employ the jps -ln command to get the process id of Java application and then use the jstack command on that process id (jstack pid) to get a thread dump. Nice documentation can be found here.
If you really in the mood to experiment, take a look at the Visual VM project that was just launched on java.net. You'll find a cool tool, based on the NetBeans platform, that helps monitor and profile Java applications. It only runs on top on Java 6, however it can work on applications based on JDK 1.4.2 or later.