简体   繁体   English

ReentrantLock和Stampedlock有什么区别? 哪一个更喜欢?

[英]What is the difference between ReentrantLock vs stampedlock? Which one to prefer?

What should be the use cases for choosing between ReentrantLock and StampedLock? 在ReentrantLock和StampedLock之间进行选择的用例应该是什么? For example, Which lock should be chosen if I have 10 Readers and 10 Writers? 例如,如果我有10个读者和10个作家,应该选择哪个锁? And which one to choose if i have 20 Readers and 1 writers? 如果我有20位读者和1位作家,该选择哪一个?

ReentrantLock is, as its name and javadocs say, reentrant. ReentrantLock是,正如它的名字和的javadoc说,折返。 StampedLock is not. StampedLock不是。

StampedLock is a low-level building block with some fragile behavior and complex interaction with the java memory model. StampedLock是一个低级构建块,具有一些脆弱的行为和与Java内存模型的复杂交互。 Its use should be avoided unless you understand all its properties and have profiled code to determine that something is actually bottlenecked on locking. 除非您了解其所有属性,并且已使用概要文件代码确定某些内容实际上是锁定瓶颈,否则应避免使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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