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:
Hashtable and ConcurrentHashMap do not allow null
keys or null
values.
Collections.synchronizedMap(Map) synchronizes all operations (get
, put
, size
, etc).
ConcurrentHashMap supports full concurrency of retrievals, and adjustable expected concurrency for updates.
As usual, there are concurrency--overhead--speed tradeoffs involved. You really need to consider the detailed concurrency requirements of your application to make a decision, and then test your code to see if it's good enough.