What's the difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?

前端 未结 19 1070
名媛妹妹
名媛妹妹 2020-11-22 11:45

I have a Map which is to be modified by several threads concurrently.

There seem to be three different synchronized Map implementations in the Java API:

    <
19条回答
  •  不知归路
    2020-11-22 12:07

    Here are few :

    1) ConcurrentHashMap locks only portion of Map but SynchronizedMap locks whole MAp.
    2) ConcurrentHashMap has better performance over SynchronizedMap and more scalable.
    3) In case of multiple reader and Single writer ConcurrentHashMap is best choice.

    This text is from Difference between ConcurrentHashMap and hashtable in Java

提交回复
热议问题