Thursday, March 5, 2009

Thread dump in Jetty

Normally if you have a problem with dead-locked threads or you want to know what is taking so long in a running application you can get the JVM to do a thread dump for you by sending the QUIT signal like this:

First get the process id using

ps | grep java

then send the quit signal

kill -QUIT <your-pid>

But this was not working for me on my server running Jetty 6.1 as installed by the .deb installation. The logs showed nothing.

After a bit of searching on the interweb I found the new (to me) method of generating stack traces using

sudo jstack <pid>

This was slightly more helpful and told me:

"Unable to open socket file: target process not responding or HotSpot VM not loaded"

At last I had something to go on and found that jstack must be run as the same user as the java process - which in the case of Jetty as installed by the debian install files is "jetty"

sudo -u jetty jstack <your-pid>

worked a treat and so did

sudo -u jetty kill -QUIT <your-pid>


1 comment:

Gary said...

Thanks. jstack was new to me too until I read this post. I was using kill -3 to view jettys threads and expecting to see the dump in one of the log files but no, it dumped itself at my colleagues terminal window because he was the one who started the process. jstack does the job, and writes the stack to my stdout. That has saved me from hacking the start script to capture the output to a log file.