[concurrency-interest] regarding StampedLock

Doug Lea dl at cs.oswego.edu
Mon Oct 15 08:34:12 EDT 2012

On 10/15/12 08:19, Yechiel Feffer wrote:
> Are the read & write locks more efficient than the ReentrantReadWriteLockmothods
> (in its non-fair mode) ? is there a reason to replace current
> ReentrantReadWriteLock with the stamped one ?

Typically yes. For example, some tests protecting TreeMaps with
StampedLock vs RRWL run very noticeably faster under
most contention levels and method mixes.
This used Optimistic mode only for a few tiny methods
like size() -- as mentioned before, effective use of ANY
Read-Write lock requires that you know something about the
data, objects, and methods they protect. This is why we cannot
offer generic RW-based collection wrappers. For example, even
method get() is not side-effect-free in LinkedHashMap, so
you cannot use a read-lock around it.

While I'm at it: Thanks to all for on- and off-list suggestions,
most of which I incorporated:


More information about the Concurrency-interest mailing list