문제

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.)

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top