Question

It is easy to output a threaddump from the Java program by calling Thread.getAllStackTraces(). I sometimes used this in a JSP to easily diagnose problems. But often another important information you need to find out is which locks are held by the threads and which locks blocked threads are trying to acquire. Is there a way to get this information via the Java API? The only thing I found is Thread.holdsLock, but this does only help if you know all the objects that might be locked, and does not tell you which locks a blocked thread is trying to acquire.

(Of course you can get this information by using tools to create a threaddump, but this option is often not easily available if the system is not on your own machine.)

Était-ce utile?

La solution

I wrote a similar answer some time back which does something similar using management extensions.

Autres conseils

Check out ThreadMXBean#getThreadInfo(). It may be what you need.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top