ConcurrentHashMap vs Synchronized HashMap

后端 未结 12 2315
北海茫月
北海茫月 2020-11-27 09:50

What is the difference between using the wrapper class, SynchronizedMap, on a HashMap and ConcurrentHashMap?

Is it just bein

12条回答
  •  [愿得一人]
    2020-11-27 10:05

    SynchronizedMap and ConcurrentHashMap are both thread safe class and can be used in multithreaded application, the main difference between them is regarding how they achieve thread safety.

    SynchronizedMap acquires lock on the entire Map instance , while ConcurrentHashMap divides the Map instance into multiple segments and locking is done on those.

提交回复
热议问题