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