Question about atomicity in ConcurrentHashMap

Zhong Yu zhong.j.yu at
Thu May 23 10:01:59 PDT 2013

On Thu, May 23, 2013 at 11:47 AM, Gernot Neppert <mcnepp02 at>wrote:

> Am 23.05.2013 18:34, schrieb Sam Pullara:
> > ConcurrentHashMap overrides computeIfAbsent and does something that will
> not compute more than once. However, it appears that they suggest not doing
> anything expensive as other operations on the map may block during the
> computation.
> >
> No, it doesn't - that's why I started this thread in the first place ;-)
> I'm using the Win32 snaphot of build 90. Maybe it's just the source
> bundle in the JDK snapshot that has not been updated?!
> see

Ideally it should be ok to invoke the function multiple times; the function
should be short and side effect free. But I guess the name of the method
forces CHM to guarantee that the function is invoked only once, so that the
behavior won't be surprising to those who don't read javadoc:)

More information about the lambda-dev mailing list