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?
Asked
Active
Viewed 1,353 times
2
-
1Related: http://stackoverflow.com/questions/26094200/what-is-stamped-locks-in-java – Thilo Dec 07 '16 at 12:36
-
@Thilo This question does not answer my question related to readers and writers. Why is it downvoted? – KayV Dec 07 '16 at 12:37
-
@Thilo Are you deliberately downvoting my other questions also? – KayV Dec 07 '16 at 13:04
-
@Veeram I could not find any solution for my problems on Stackoverflow, so i posted the questions. And in the meanwhile when i tried i found the solution myself. That is why i posted the answers too. Is there any fault in doing this? Even for this particular question, I have not got any perfect solution. I don't think downvoting the questions from your side is valid. – KayV Dec 07 '16 at 13:16
-
1I'm not trying to make a point here. All I'm saying is try first for a little while before you post your questions. Please read the api docs. – s7vr Dec 07 '16 at 13:17
-
@Veeram You are just over using your rights of down voting. – KayV Dec 07 '16 at 13:20
-
1like I said I'm not trying to make a point here. I'll go ahead n remove the downvote if thats all you care if I can. – s7vr Dec 07 '16 at 13:21
-
@Veeram Voting matters. Pls remove your down votes. – KayV Dec 07 '16 at 13:22
-
2The documentation is quite detailed, so you really should at least point out which part of the documentation is unclear – the8472 Dec 07 '16 at 16:03
-
@KaranVerma I have not voted (either way) on any of your questions. – Thilo Dec 07 '16 at 23:40
1 Answers
5
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.

the8472
- 40,999
- 5
- 70
- 122