JDK1.7中关于多线程操作HashMap的成环以及丢失问题
作者:互联网
文章目录
1. 预备知识
扩容产生的条件:
- 如果HashMap初始化的时候,没有设置初始容量,那么初始容量默认为16,扩容阈值threshold为16*0.75f=12;
- 如果设置了初始容量,那么首次扩容阈值threshold为初始容量。
HashMap的插入
- JDK1.7的插入是头插法
public HashMap(int initialCapacity, float loadFactor) {
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal initial capacity: " +
initialCapacity);
if (initialCapacity > MAXIMUM_CAPACITY)
initialCapacity = MAXIMUM_CAPACITY;
if (loadFactor <= 0 || Float.isNaN(loadFactor))
throw new IllegalArgumentException("Illegal load factor: " +
loadFactor);
this.loadFactor = loadFactor;
threshold = initialCapacity;// 标签:hash,HashMap,JDK1.7,len,next,线程,newTable,Entry,多线程
来源: https://blog.csdn.net/qq_42898299/article/details/122700404