How to debug hanging threads in JVM?

I am running a robust Java program on a remote Ubuntu server where I have root privileges. After some time, the use on some processor cores reaches 100%. Logs show nothing suspicious, and the application is still running, but with reduced bandwidth.

How can I debug the JVM to find out the reason for this while it is still working?

+2
source share
3 answers

One VisualVM parameter that is included in the JDK since Java 1.6. I found this useful in some situations in the past.

You can connect to local applications or remote applications.

To connect to the remote application, run jstatd on the remote server, and then run VisualVM locally and enter the IP address of your server. You should be given a list of running Java applications, including the one you want to learn. If you have any problems listing your application, good documentation is available on the VisualVM website.

+2
source

Connect to a process using jvisualvm

This tool will allow you to connect to the running process and view all threads and their status. This can show you which stream is the culprit, just looking at the fact that he is awake all the time. You can dump a thread to see the stack trace for each thread and see what each thread does.

This is a very powerful tool for this kind of debugging. It is distributed only with the JDK, so you will need more than just the JVM runtime to access. Make sure you install the same version of the JDK as the JVM.

You will need your X-display to be redirected for this.

+2
source

If you want to see the stack trace on linux, just type kill -SIGQUIT <java-program-pid> . This is one way to see where the code is executing.

+1
source

All Articles