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