ConcurrentHashMap is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details.
I am confused with Thread Safety vs Synchronization details, can any one tell me an example?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Hashtablehas every methodsynchronized, and it’s a publicly available information. For example, you can inherit fromHashtable, add moresynchronizedmethods—and know you’re doing mostly OK as you use the same synchronisation mechanism.Moreover, your code can use
synchronized (myHashTable)block, effectively ensuring nomyHashTablemethods are called from other threads while you’re in this block.That’s all “synchronization details” which are available to you and which you are free (while discouraged) to use.
Not so with
ConcurrentHashMap: it’s as thread safe (and even more so in some sense, see e.g. the answer by Peter Lawrey) asHashtable, but you’re not told how this thread safety is achieved. As a result, you cannot abuse or extend it as you like: you’re supposed to use it as it is.