1

I have a Java program on my local machine that becomes unresponsive after sometime and appears to freeze without making further progress. I guess it blocks somewhere (it is accessing remote resources over both HTTP and JDBC so a blocking situation is likely). I am trying to connect to it to see a view of the main thread's stack so as to understand where the block occurred. Both jvisualvm and jconsole list the JVM in question (among others running in my system) but both fail to connect.

jconsole balks with "connection failed" (even when I try the insecure option).

jvisualvm appears to connect but when I hit the 'sampler' tab to see the stack it complains with the screenshot below:

enter image description here

The thing is I am using the same utilities (jconsole and jvisualvm) to connect to other JVMs in my system which I have invoked without using any of the JMX options mentioned in this answer and I don't have any issues. How can I get the stack of this unresponsive JVM to see where it blocks?

Community
  • 1
  • 1
Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331

2 Answers2

4

I faced a similar issue today with a JVM that was completely stuck and I was unable to properly attach jconsole/jvisualvm to it. Also kill -3 <PID> was unsuccessful (no Thread dump).

I was able to trigger a coredump of the JVM using kill -11 <PID> and feed that into jstack as follows: jstack /path/to/java /path/to/core.file. From the jstack output I was able to extract some useful stack information.

Arnoud
  • 96
  • 2
  • 1
    kill -11 initially responded with "*Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again*". After running **ulimit** the core was produced. – Marcus Junius Brutus Mar 22 '14 at 19:34
2

You could just collect a thread dump with kill -3 <PID>.

This will show you all the threads and where they are blocked.

Aleš
  • 8,896
  • 8
  • 62
  • 107
  • Wouldn't that show the stack of the JVM code instead? I am interested in the threads of the Java code that gets interpreted by the JVM. – Marcus Junius Brutus Mar 18 '14 at 10:07
  • This would show all the threads in the VM, the application and the system threads and their states. You can then see where your threads are blocking. – Aleš Mar 18 '14 at 15:39
  • 1
    OK, both -3 and -11 worked in my case. I am accepting the other answer as it also mentioned the *jstack* tool – Marcus Junius Brutus Mar 22 '14 at 19:44