How does jstack -F affect a running Java process?

Jordan Bentley picture Jordan Bentley · Aug 21, 2012 · Viewed 22k times · Source

I am trying to diagnose a problem where a Java web application I'm using (Jenkins) becomes unresponsive. If I run jstack without the -F flag it doesn't give me anything, but if I put the flag in to force a thread dump not only do I get a result, but the application starts responding and goes on as if nothing had happened until it eventually stops responding again.

What does jstack -F flag do that would affect a running JVM and cause an unresponsive application to start responding again?

Answer

sbridges picture sbridges · Aug 26, 2012

You can see the source to jstack here. The -F argument changes how jstack connects to the jvm. With -F (or -m) JStack connects to the jvm using the java debugger interface. If a pid is specified, JStack connects with the SA PID Attaching Connector which says,

The process to be debugged need not have been started in debug mode(ie, with -agentlib:jdwp or -Xrunjdwp). It is permissable for the process to be hung.

I don't know why it would cause an unresponsive application to start responding again, but the link above also says,

The process is suspended when this connector attaches and resumed when this connector detaches.

This may have an effect.