[问题一]如何理解HashMap、HashTable、ConcurrentHashMap

一、HashMap

数组+链表

参考博客:https://blog.csdn.net/Jae_Peng/article/details/79562432

二、HashTable

synchronized+HashMap,线程安全,但多线程争抢同一把锁,耗性能

二、ConcurrentHashMap

jdk1.7:segment数组(固定大小,使用ReentrantLock可重入锁)+数组+链表

jdk1.8:node(可扩展,使用synchronized+CAS)+链表/红黑树(超过8位用红黑树,提升查询效率)

参考博客:

https://blog.csdn.net/stone_tomcate/article/details/100110453

https://www.jianshu.com/p/865c813f2726

https://www.jianshu.com/p/1e1a96075256

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章