ThreadDump to the rescue


We were facing a strange problem with our swing application. It was hanging randomly, neither was the CPU consumption going high nor the memory. So it had to be some sort of a deadlock issue. But we had no clue about where/what might be causing the deadlock. A ThreadDump at the time of deadlock would have been handy to figure out what all the threads were doing at that time.

Most of the Java Developers have been using the nifty Ctrl+Break key combination to get the thread dumps. It is fine for applications that can be launched from commandline but for applications which are launched using Java Web Start are a different beast altogether. And in our case it turned out that this hanging only occured when the application was launched using JWS. So how do we get the ThreadDump?

No worries. Java has a perfect tool bundled with the JDK – JStack. A perfect tool to get the thread dump of any java application on demand. Yeah on Demand! Thats the beauty of the tool. And its so simple to use. The application syntax is:

jstack [ option ] pid 

jstack [ option ] executable core 

jstack [ option ] [server-id@]remote-hostname-or-IP

norder to get the Process ID (PID) on windows use the TaskManager. It has the option of showing the PID. After this you just have to execute the command when you want to get the ThreadDump. No need to run the application through a commercial profiler to get the thread dumps any more. And also you dont have to run the application in Debug mode either. You can get the thread dump of any java application any time 🙂

 PID in TaskManager

I will be posting more details about the bug that we encountered and other similar toosl which help in identifying deadlocks and analyzing thread dumps. So stay tuned.

Advertisements
ThreadDump to the rescue

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s