[英]How is 'synchronized' related to ReentrantLock?
From what I have read, synchronized
block of code means intrinsic re-entrant lock of an object, and ReentrantLock
is an abstraction to achieve re-entrance. 据我了解,
synchronized
代码块意味着对象的固有重入锁,而ReentrantLock
是实现重ReentrantLock
的抽象。 Is there a need to use ReentrantLock
other than calling lock()
and unlock()
methods from different methods, pieces of codes? 除了从不同的方法,代码段调用
lock()
和unlock()
方法之外,是否需要使用ReentrantLock
?
Documentation of ReentrantLock ReentrantLock的文档
A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities.
具有与使用同步方法和语句访问的隐式监视器锁相同的基本行为和语义的可重入互斥锁,但具有扩展功能。
Those extended capabilities are related to the monitoring of the synchronization, as well as customization of the behavior. 这些扩展功能与同步监视以及行为自定义有关。 Looking at the method list should speak for itself.
查看方法列表应该说明一切。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.