Under HashMap thread-safe multi-threaded environment

Study notes:

  1. The main reason for insecurity thread at HashMap in a multithreaded environment is put (key, value) operation will cause an infinite loop, Entry hashMap list of data to produce a ring structure, next down for it, but never find the last one, resulting in death cycle.
  2. ConcurrentHashMap in how to position an element in what position, how to ensure thread safety?

          JDK1.7 and earlier:

          get () method targeting segment: key hashcode for a high re-hash value modulo

          Positioning table: key to re-hashcode hash value modulo

          Sequentially scan the linked list, or find an element, or null

Released seven original articles · won praise 1 · views 328

Guess you like

Origin blog.csdn.net/baidu_36882394/article/details/103384570