On 04/25/2018 10:06 AM, Claes Redestad wrote:
Besides, CHM.computeIfAbsent has a non-synchronizing fast-path for when the key exists,
lines 1731-1734:

            else if (fh == h    // check first node without acquiring lock                      && ((fk = f.key) == key || (fk != null && key.equals(fk)))
                     && (fv = f.val) != null)
                return fv;

Sorry, you're (almost) right! I confused it with CHM.compute()...

The almost part is that lock is avoided only when the match is found in the 1st linked node of the bucket. If there is a hash collision (very unlikely) and the entry is in a 2nd or subsequent node in the list, the lock is still used. So there's almost no locks used... And if there's no hot contention going on, there's no need for prefacing with .get().

Regards, Peter

Reply via email to