简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM