据我所知,同步
代码块意味着对象的固有可重入锁,而ReentrantLock
是对实现重新进入。除了从不同的方法、代码片段调用lock()
和unlock()
方法之外,是否还需要使用ReentrantLock
?
最佳答案
Documentation of 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.
这些扩展功能与同步监控以及行为定制相关。查看方法列表应该不言而喻。
关于java - 'synchronized'与ReentrantLock有何关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22321404/