[concurrency-interest] generalise computeIfAbsent() for ConcurrentMap

Doug Lea dl at cs.oswego.edu
Wed Jun 20 11:51:04 EDT 2012


On 06/20/12 11:26, Aleksey Shipilev wrote:
> Yes, I saw that coming. Continuing on my point, if computeIfAbsent()
> ought to be the placeholder for the usual code people do around
> putIfAbsent(), it seems to be presumed mapper function is side-effect
> free.

That was part of our reasoning for not including these methods
in the first place. But we now know that many users disagree.
See for example the paper below that found errors in
user code due to either not implementing the
putIfAbsent version correctly or actually needing a version
that guarantees once-only computation. Supporting the stronger
versions hits both these cases at once. (And those people
who prefer weaker version can still get it using putIfAbsent.)

http://www.cs.tau.ac.il/~ohads/docs/OOPSLA11.pdf
Testing Atomicity of Composed Concurrent Operations
Ohad Shacham, Nathan Bronson, Alex Aiken, Mooly Sagiv, Martin Vechev, and Eran 
Yahav. OOPSLA'11

-Doug


More information about the Concurrency-interest mailing list