Thread-safe HashMap
Because multi-threaded environment, the use of Hashmap be put action will cause an infinite loop, resulting in CPU utilization close to 100%, so you can not use a HashMap in concurrency.
Inefficient container HashTable
HashTable container using synchronized to ensure thread safety, but HashTable in the fierce competition in the thread very inefficient. Because when one thread to access the HashTable synchronization method, synchronization method HashTable other threads access may be blocked or enter the polling state. Such as thread 1 put to use to add elements, thread 2 will not be able to add elements, and also can not use the get method to get the elements using the put method, so the lower the efficiency of more intense competition.
HashMap,HashTable,ConcurrentHashMap
Let me talk about the difference between these three Map:
HashTable
- + Linked list to achieve the underlying array, whether key or value can not be null , thread- safe , thread-safe way to achieve lock the entire HashTable when data is modified, low efficiency, ConcurrentHashMap do the relevant optimization
- The initial size of 11 , expansion: newsize = olesize