What is the difference between a ConcurrentHashMap and a Hashtable in Java?
Which is more efficient for threaded applications?
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.
ConcurrentHashMapuses multiple buckets to store data. This avoids read locks and greatly improves performance over aHashTable. Both are thread safe, but there are obvious performance wins withConcurrentHashMap.When you read from a
ConcurrentHashMapusingget(), there are no locks, contrary to theHashTablefor which all operations are simply synchronized.HashTablewas released in old versions of Java whereasConcurrentHashMapis a java 5+ thing.HashMapis the best thing to use in a single threaded application.