Implementation principle of ArrayList, LinkedList, Hashtable, HashMap, ConcurrentHashMap, HashSet

The collection needs to master the implementation principles of ArrayList, LinkedList, Hashtable, HashMap, ConcurrentHashMap, and HashSet. It is good to be able to answer fluently, of course, to master the CopyOnWrite container and Queue. In addition, one more thing, ConcurrentHashMap questions are asked a lot in the interview, probably because this class can derive a lot of questions. Regarding ConcurrentHashMap, I provide three answers or research directions:

 

  Lock segmentation technology of ConcurrentHashMap?

            The reason why the HashTable container is inefficient in a highly competitive concurrent environment is because all threads accessing the HashTable must compete for the same lock. If there are multiple locks in the container, each lock is used to lock part of the data in the container. , then when multiple threads access the data of different data segments in the container, there will be no lock competition between threads, which can effectively improve the efficiency of concurrent access. This is the lock segmentation technology used by ConcurrentHashMap. First, the data is divided into segments storage, and then assign a lock to each segment of data. When a thread occupies the lock to access one segment of data, other segments of data can also be accessed by other threads.

 

  Does the reading of ConcurrentHashMap need to be locked and why?

 

  Is the iterator of ConcurrentHashMap a strongly consistent iterator or a weakly consistent iterator

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326308325&siteId=291194637