1. Hashtable:
(1) is a two-dimensional array containing one-way chain, the table array is entry<k,v> storage, entry object;
(2) The value to be placed cannot be null;
(3) thread-safe, all methods are modified with synchronized;
2. HashMap:
(1) equivalent to the upgrade version of Hashtable;
(2) can be placed in a null value;
(3) Based on the hash table;
(4) stored in the order of insertion;
(5) Thread is unsafe: because of multithreaded environment, using HASHMAP to put operation will cause a dead loop, resulting in CPU utilization near 100%, so in the concurrency situation can not use HashMap;
3. Concurrenthashmap:
Through analysis Hashtable know, synchronized is for the whole hash table, that is, each time lock the whole table to let the thread monopoly, security behind is a huge waste, the eye unique Doug Lee immediately took out the solution----concurrenthashmap, is also thread-safe.
I think it can be understood that a segment equivalent to Concurrenthashmap is a hashtable;
The main difference between Concurrenthashmap and Hashtable is the granularity of the lock and how it is locked.
4. TreeMap:
(1) based on red and black trees;
(2) is an orderly storage;
(3) You can define the sequencer;
5. What is the difference between Hashtable and concurrenthashmap ?
Same point:
(1) Hashtable and Concurrenthashmap are thread-safe and can be run in multi-threaded environments;
(2)both key and value cannot be null.
Different points:
The main difference is the performance of the two
(1) the inefficient Hashtable :
Hashtable containers use synchronized to ensure thread safety, but Hashtable is inefficient in the event of intense online competition. Because when a thread accesses the Hashtable synchronization method, other threads may enter the blocking or polling state when they access the Hashtable synchronization method. If thread 1 adds elements using put, thread 2 cannot add elements using the Put method, nor can it use the Get method to get elements, so the more competitive the more efficient the less.
(2) Concurrenthashmap with lock segment technology :
The reason why Hashtable containers are inefficient in a competitive concurrency environment is that all threads accessing Hashtable must compete for the same lock, if there are multiple locks in the container, and each lock is used to lock a portion of the container's data, then when multithreading accesses data from different data segments in the container, There is no lock competition between the threads, which can effectively improve the efficiency of concurrent access, which is the lock segmentation technique used by Concurrenthashmap, first dividing the data into a section of storage, then giving each piece of data a lock, when a thread occupies a lock to access one of the data, Data from other segments can also be accessed by other threads.
Java Basic Knowledge Enhancement Collection Framework note 78:concurrenthashmap Concurrenthashmap, Hashtable, HashMap, treemap differences