Get deadlock detection from a running program or dump in Java

I have a piece of running java software that is stuck. I would like to get an idea inside, but have no idea how to do this.

Is there any tool that I can give the PID, and it will tell me where each thread is located, and maybe several variable values? I am running linux.

I more or less know what causes the problem, but there are a few more possible cases, so an exact definition would be nice.

I can’t reproduce the error, because it appears only every few days and never appeared during debugging, so this is a unique change in meeting the enemy.

Any ideas?

+2
source share
3 answers

In fact, you can try to use visualvm + its monitoring plugin . You can also dump the stream, view the stack traces of the ant stack of their state. You can also use jconsole to detect deadlocks. Both tools are part of the JDK. Jconsole

There is more information on using visualvm for stream analysis.

+9
source

You can take a stream dump. You can use kill -3 PID , where PID is the identifier of your process. This will cause the stream dump to be output to the standard output of your program.

This will show you what each thread does, but will not give you any information about the variables. Despite this, thread threads are really useful. I would start there. If you still cannot fix this problem, you can use something like jmap (a JVM tool, free but harder to use) or YourKit (a paid product, but very good) to take a snapshot and examine the variables.

Some jmap info: Profiling Java memory with jmap and jhat

+4
source

In recent JVMs (OpenJDK / Oracle Java 7 or higher), if you take a bunch of heaps (using either VisualVM or jmap), it also contains dump stacks of all currently running threads, with links to the corresponding objects in the heap. You can then view the stacks by opening the heap dump in VisualVM.

0
source

Source: https://habr.com/ru/post/1247103/


All Articles