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

Clarify that ConcurrentHashMap compute methods mapping functions execute at most once

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 14
    • None
    • core-libs
    • None

      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

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

              Created:
              Updated:
              Resolved: