jitron
jitron

Reputation: 135

How can I know the lock information in java?

Is there any tool or way that can get all the information about the locks in java?

for example, if there is a java program, it creates two threads, and both threads require locks for some variable. Is there any tools that can output the information like which thread locks which variable?

Upvotes: 3

Views: 385

Answers (1)

Art Licis
Art Licis

Reputation: 3679

You can use ThreadInfo#getLockedSynchronizers() (JavaDoc) via ThreadMXBean to get array of LockInfo on currently owned locks on threads. LockInfo will tell you just class name & identity hashcode of a lock, but that's sufficient in tracing lock objects.

Upvotes: 1

Related Questions