hashmap造成死循环
2016-04-16 16:27
274 查看
转载地址:/article/6109929.html
注:
这是transfer方法里面的一段代码
注:
public V put(K key, V value) { ...... //算Hash值 int hash = hash(key.hashCode()); //会出现相同hash值 int i = indexFor(hash, table.length); //如果该key已被插入,则替换掉旧的value (链接操作) for (Entry<K,V> e = table[i]; e != null; e = e.next) { Object k; //key.equals(k)针对字符串,这样s1="abc"和s2=new String("abc")key相同 if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { V oldValue = e.value; e.value = value; e.recordAccess(this); return oldValue; } } modCount++; //该key不存在,需要增加一个结点 addEntry(hash, key, value, i); return null; }
这是transfer方法里面的一段代码
do { Entry<K,V> next = e.next; // <--假设线程一执行到这里就被调度挂起了 int i = indexFor(e.hash, newCapacity); //指向第一个newTable[i]中的第一个Entry e.next = newTable[i]; //自己为newTable[i]中的第一个Entry newTable[i] = e; e = next; } while (e != null);
相关文章推荐
- HDU NO.4324 Triangle LOVE(拓扑排序)
- python中enumerate 函数
- vim支持lua
- xcode7下多出来的告警修复
- Linux下信号量的P.V操作如何保证其原子性
- 分拣存储3-HashMap实现学生选课
- Git客户端TortoiseGit(Windows系统)的使用方法
- uva11584
- linux下运行eclipse出错的解决方法
- ACM-2008 数值统计
- 【USACO题库】3.3.3 Camelot亚瑟王的宫殿
- 响应式设计
- 题目1002:Grading
- Activity的生命周期和启动模式
- sql server 数据库mdf与ldf文件的导入
- Qt应用程序自动重启(零零散散)
- linux常用命令
- nyoj 63 小猴子下落(二叉树)
- 判断平年闰年
- struct和typedef struct的区别