Quantcast
Channel: ConcurrentHashMap and putAll() method - Stack Overflow
Viewing all articles
Browse latest Browse all 3

ConcurrentHashMap and putAll() method

$
0
0

Normally (ie. not concurrently), putAll() cannot be more efficient than using lot's of calls to put(), even assuming that you exclude the cost of building the other Map that you pass to putAll(). That's because putAll() will need to iterate the passed Map's elements, as well as running through the algorithm for adding each key value pair to the Map that put() executes.

But for a ConcurrentHashMap, does it make sense to construct a regular Map and then use putAll() to update it? Or should I just do 10 (or 100, or 1000) calls to put()?

Does the answer change for multiple calls to putIfAbsent()?

Thanks!


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images