[concurrency-interest] ConcurrentHashMap computeIfAbsent

Doug Lea dl at cs.oswego.edu
Sun Dec 21 10:47:29 EST 2014


On 12/21/2014 09:59 AM, Viktor Klang wrote:
> For "computeIfAbsent"-style maps which are intended for multithreaded use, I
> tend to prefer to use ConcurrentMap[Key, CompletionStage[Value]],

Right. Prior to jdk8, we suggested variations of this and other
techniques that remain preferable in many cases. However, the
most common CHM user error was trying (but failing) to emulate
what is now supported as computeIfAbsent. This is an improvement,
but leads to new (much less common) kinds of potential errors.
We cannot automatically eliminate or trap all of them. It
might be possible to do more than we do now, either internally
(inside CHM) or, more likely, with improved developer tools.

-Doug



More information about the Concurrency-interest mailing list