Alex Rivera | Logout

ConcurrentHashMap and Hashtable in Java

Asked 2012-09-28T19:45:54.200
94

What is the difference between a ConcurrentHashMap and a Hashtable in Java?

Which is more efficient for threaded applications?

Edit
Report

1 Answer

125

ConcurrentHashMap uses multiple buckets to store data. This avoids read locks and greatly improves performance over a HashTable. Both are thread safe, but there are obvious performance wins with ConcurrentHashMap.

When you read from a ConcurrentHashMap using get(), there are no locks, contrary to the HashTable for which all operations are simply synchronized. HashTable was released in old versions of Java whereas ConcurrentHashMap is a java 5+ thing.

HashMap is the best thing to use in a single threaded application.

answered 2012-09-28T19:48:12.277

Your Answer