Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8231592

Clarify that ConcurrentHashMap compute methods mapping functions execute at most once

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 14
    • Component/s: core-libs
    • Labels:
      None

      Description

      ConcurrentHashMap (unlike ConcurrentSkipListMap) was architected to run a mapping function at most once in methods compute, computeIfAbsent, computeIfPresent (essentially by locking the key's bin).

      But this should be better documented and tested.

      There was wording added to the computeIfAbsent spec, but unfortunately not to compute and computeIfPresent, suggesting that computeIfAbsent's behavior is somehow distinct when it is not. Also, computeIfAbsent's spec should be clarified. I had trouble with """The entire method invocation is performed atomically, so the function is applied at most once per key. """
      All ConcurrentMap implementations update atomically, so perhaps simply say """the function is applied at most once per key"""

      Discussion at
      https://concurrency.markmail.org/thread/vlm4a4ouho7snqfb

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                martin Martin Buchholz
                Reporter:
                martin Martin Buchholz
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: