ConcurrentHashMap和Collections.synchronizedMap(Map)有什麼區別?

問題:

I have a Map which is to be modified by several threads concurrently. 我有一個地圖,該地圖將同時被多個線程修改。 html

There seem to be three different synchronized Map implementations in the Java API: Java API中彷佛有三種不一樣的同步Map實現: java

  • Hashtable
  • Collections.synchronizedMap(Map)
  • ConcurrentHashMap

From what I understand, Hashtable is an old implementation (extending the obsolete Dictionary class), which has been adapted later to fit the Map interface. 據我瞭解, Hashtable是一箇舊的實現(擴展了過期的Dictionary類),後來對其進行了調整以適合Map接口。 While it is synchronized, it seems to have serious scalability issues and is discouraged for new projects. 雖然它同步的,但彷佛存在嚴重的可伸縮性問題 ,所以不建議用於新項目。 spa

But what about the other two? 可是其餘兩個呢? What are the differences between Maps returned by Collections.synchronizedMap(Map) and ConcurrentHashMap s? Collections.synchronizedMap(Map)ConcurrentHashMap返回的Collections.synchronizedMap(Map)之間有什麼區別? Which one fits which situation? 哪種適合哪一種狀況? .net


解決方案:

參考一: https://stackoom.com/question/28q0/ConcurrentHashMap和Collections-synchronizedMap-Map-有什麼區別
參考二: https://oldbug.net/q/28q0/What-s-the-difference-between-ConcurrentHashMap-and-Collections-synchronizedMap-Map
相關文章
相關標籤/搜索