[問題一]如何理解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

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