> 文章列表 > ConcurrentHashMap

ConcurrentHashMap

ConcurrentHashMap

一、ConcurrentHashMap

1.1 存储结构

ConcurrentHashMap是线程安全的HashMap

ConcurrentHashMap在JDK1.8中是以CAS+synchronized实现的线程安全

CAS:在没有hash冲突时(Node要放在数组上时)

synchronized:在出现hash冲突时(Node存放的位置已经有数据了)

存储的结构:数组+链表+红黑树

ConcurrentHashMap

1.2 存储操作

1.2.1 put方法

public V put(K key, V value) {