Java Docs for Lock在方法 lock
、lockInterruptically
和 tryLock
的文档中包含以下语句。
A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.
Java 8 API 中是否有任何 Lock
接口(interface)的实现实际上尝试检测此类“错误使用”?
最佳答案
因此,经过更多研究,我得出的结论是答案显然是:
不。标准 Java 8 API 中的 Lock 实现都没有尝试执行类似的操作。
但是,有些库具有检测(潜在)死锁的机制,这些机制利用锁定方法的 Java 文档中给出的显式权限来引发 RuntimeException
。这种机制的一个例子是 Guava's CycleDetectingLockFactory Louis Wasserman 在评论中提到了这一点。
关于java - 是否有执行死锁检测的 Lock 实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33939927/