java interview test sites -HashTable / HashMap / ConcurrentHashMap

HashTable

  • + Internal data structure is an array list, key-value pair is null, thread-safe, but the whole table lock is locked, poor performance allowed / inefficiencies

HashMap

  • Structure with HashTable, to allow key is null, thread-safe,
  • The default size of the initial 16 (fixed to a power of 2),
  • The default expansion threshold is 0.75, for the expansion mode, and then inserted into the first expansion, it will produce invalid expansion,
  • Defaults to a single chain length of 8, when more than the list automatically converted to red-black tree structure, the tree structure when the length is less than 6, back into the list

ConcurrentHashMap

  • After jdk1.5 on HashTable upgraded version, the performance efficiency of all aspects of a huge improvement,
  • 1.5-1.7 segment used in the version as a division unit, locks the segment during operation, initially the default segment 16, uses a reentrant lock ReentrantLock
  • After giving up 1.8 segment, using the same data structure HashMap, Node, using mechanisms such as optimistic locking CAS, CAS operation using three node to ensure that some of the atoms of the operation, in this way instead of the lock, the lock is reduced particle size, to enhance the concurrency

 

Guess you like

Origin www.cnblogs.com/7motor28/p/11241791.html