简体   繁体   中英

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

What should be the use cases for choosing between ReentrantLock and StampedLock? For example, Which lock should be chosen if I have 10 Readers and 10 Writers? And which one to choose if i have 20 Readers and 1 writers?

ReentrantLock is, as its name and javadocs say, reentrant. StampedLock is not.

StampedLock is a low-level building block with some fragile behavior and complex interaction with the java memory model. Its use should be avoided unless you understand all its properties and have profiled code to determine that something is actually bottlenecked on locking.

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