I was going to implement some code which needs a synchronized data structure. I came up with HashTable and Collections.synchronized(HashMap). I wouldn’t be needing ConcurrentHashMap for this. I was wondering which one of the two would be better.
PS : I will be calling a lot of getter of this object and they would not be at the same time. So their is no problem with concurrency issue also.
ConcurrentHashMapis much more scaleable: http://www.javamex.com/tutorials/concurrenthashmap_scalability.shtmlHashTableandCollections.synchronized(HashMap)provide with the same performance, but they are conditionally thread-safe (i.e. they are not fully thread-safe)If there are a lot read operations, I would recommend to wrap it with read-write locks:
UPDATE:
It doesn’t guarantee that you don’t need synchronization.