[concurrency-interest] Concurrent Hash Map javadoc question

Keith Turner keith at deenlo.com
Wed Sep 18 13:56:08 UTC 2019


On Tue, Sep 17, 2019 at 10:08 PM Benjamin Manes <ben.manes at gmail.com> wrote:
>
> All three state that "The entire method invocation is performed atomically" and computeIfAbsent merely explains this with the addition "so the function is applied at most once per key." Since all computations are atomic operations in ConcurrentHashMap, this seems to be implied in the other cases rather than explicitly clarified.

I found myself wondering if atomically just meant mutually exclusive
execution OR did it mean mutually exclusive execution and at most once
execution.  I strongly suspect it means the latter.   ConcurrentMap
and ConcurrentSkipListMap are very clear about the more than once
execution semantics.  ConcurrentHashMap is clear about the at most
once semantics for one function.  The absence of information on the
other functions concerns me when everything else is so explicit.

When considering lambda with side effects, I want to ensure the code
is correct now and for future versions of Java.  The word atomically
would have to unambiguously mean the same thing to everyone in order
to maintain at most once execution semantics going forward.  I am not
sure everyone would agree on that meaning.  If that is the intent of
the function and word, it would be nice to explicitly state it.

>
> On Tue, Sep 17, 2019 at 6:36 PM Martin Buchholz via Concurrency-interest <concurrency-interest at cs.oswego.edu> wrote:
>>
>> I think this doc difference is intentional.
>>
>> In case of a retry loop, the value may have changed in the case of computeIfPresent or compute and so the function must be called again with the new value.
>>
>> On Tue, Sep 17, 2019 at 4:36 PM Martijn Verburg <martijnverburg at gmail.com> wrote:
>>>
>>> Hi Keith,
>>>
>>> I think this is one for concurrency interest to answer.
>>>
>>> Cheers,
>>> Martijn
>>>
>>>
>>> On Tue, 17 Sep 2019 at 12:48, Keith Turner <keith at deenlo.com> wrote:
>>>
>>> > The javadoc for ConcurrentHashMap.computeIfAbsent() states the
>>> > remapping function is applied at most once.  The functions
>>> > computeIfPresent() and compute() do not explicitly state if the
>>> > remapping functions could possibly be run multiple times. Does anyone
>>> > know if computeIfPresent() and compute() are guaranteed to only run
>>> > the remapping functions at most once?  If so, should the javadoc be
>>> > updated?
>>> >
>>> > Thanks,
>>> >
>>> > Keith
>>> >
>>
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest


More information about the discuss mailing list