ConcurrentHashMap was introduced in 1.5 as a part java java.util.concurrent package. Before that the only way to have a threadsafe map was to use HashTable or Collections.synchronizedMap(Map).
For all the practical purpose (multithread environment),ConcurrentHashMap is sufficient to address the needs except one case wherein a thread needs a uniform view of the map.
My question is, apart from having a Uniform View of the map, are there any other scenarios wherein ConcurrentHashMap is not an option ?
This is a stretch but I will give it as a use case.
If you needed a thread-safe Map implementation which you can do some extra compound operation on which isn’t available via
ConcurrentMap. Let’s say you want to ensure two other objects don’t exist before adding a third.Again this is a stretch, but you would not be able to achieve this with a CHM while ensuring atomicity and thread-safety. Because all operations of a
Hashtableand itssynchronizedMapcounter part synchronize on the instance of the Map this ensures thread-safety.At the end of the day I would seldom, if ever, use a
synchronizedMap/Hashtableand I suggest you should do the same.