[Solved] In JDK1.8, is it necessary to use ConcurrentHashMap on all occasions that require synchronization?

[ad_1]

No, it is not necessary to replace use of Collections.synchronizedMap with ConcurrentHashMap when used by multiple threads.

The Concurrent Collections section in the javadoc for package java.util.concurrent says:

“Synchronized” classes can be useful when you need to prevent all access to a collection via a single lock, at the expense of poorer scalability. In other cases in which multiple threads are expected to access a common collection, “concurrent” versions are normally preferable.

As you can see, both Collections.synchronizedMap and ConcurrentHashMap can have their uses.

See also “What’s the difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?”.

[ad_2]

solved In JDK1.8, is it necessary to use ConcurrentHashMap on all occasions that require synchronization?