search

Home  >  Q&A  >  body text

java - ConcurrentHashMap 多线程获取数据时保证其他线程不会插入或者影响?

ConcurrentHashMap 多线程获取数据时保证其他线程不会插入或者影响??

迷茫迷茫2802 days ago728

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:51:45

    I don’t understand what the poster wants to ask.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:51:45

    Synchronize or use ThreadLocal

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:51:45

    ConcurrentHashMap is thread-safe, whether it is put or get

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:51:45

    What the poster wants to ask is whether ConcurrentHashMap will block the put operation when getting?

    No
    because the array of ConcurrentHashMap is declared like this: transient volatile Node<K,V>[] table;
    The get operation just reads the current table array: tab = table. There is no lock.

    So it will not block the put operation

    reply
    0
  • Cancelreply