'concurrentHashMap.merge(key,1,Integer::sum) : Is this operation threadsafe? [closed]
concurrentHashMap.merge(key,1,Integer::sum)
Is the above operation thread-safe? What is the best way to make it threadsafe?
Solution 1:[1]
The operation is atomic and hence it is thread-safe, from the docs
The entire method invocation is performed atomically. Some attempted update operations on this map by other threads may be blocked while computation is in progress, so the computation should be short and simple, and must not attempt to update any other mappings of this Map.
Solution 2:[2]
ConcurrentHashMap class is thread-safe
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Cayman |
