ConcurrentHashMap

ConcurrentHashMap是HashMap的线程安全版本的实现版本;

ConcurrentHashMap结构图:和HashMap类似,ConcurrentHashMap使用了一个table来存储Node,ConcurrentHashMap同样使用记录的key的hashCode来寻找记录的存储index,而处理哈希冲突的方式与HashMap也是类似的,冲突的记录将被存储在同一个位置上,形成一条链表,当链表的长度大于8的时候会将链表转化为一棵红黑树

【知识点】

  • HashMap允许一个key和value为null,而ConcurrentHashMap则不允许key和value为null,否则抛出NullPointerException

【参考资料】

http://www.infoq.com/cn/articles/ConcurrentHashMap

https://blog.csdn.net/yan_wenliang/article/details/51029372

https://www.jianshu.com/p/c0642afe03e0

results matching ""

    No results matching ""