Java – concurrent HashMap document description
Concurrent HashMap is fully interoperable with hashtable in programs that depend on its thread safety but not on its synchronization details
I'm confused about the details of thread safety and synchronization. Can anyone tell me an example?
Solution
Hashtable synchronizes each method, and it is publicly available information For example, you can inherit from hashtable, add more synchronization methods - and know that most of them are OK when you use the same synchronization mechanism
In addition, your code can use the synchronized (myhashtable) block to effectively ensure that the myhashtable method is not called from other threads when you are in this block
This is all the sync details available and you can use them for free (though not encouraged)
Concurrenthashmap is not like this: it is thread safe (in a sense, see Peter Lawley's answer for example) as a hashtable, but you are not told how this thread safety is implemented Therefore, you cannot abuse or extend it: you should use it as is