Hashmap - ConcurrentHashMap and Hashtable in Java

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

   This question already has an answer here:
    * /questions/510632/whats-the-difference-between-concurrenthashmap-and-collections-synchronizedmap /questions/510632/whats-the-difference-between-concurrenthashmap-and-collections-synchronizedmap 16 answers

Answers

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.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/12646404/concurrenthashmap-and-hashtable-in-java

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils