加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 多线程如何破坏Hashmap的内部结构

发布时间:2020-12-15 00:21:47 所属栏目:Java 来源:网络整理
导读:在 Java 8中,真正不耐烦的Horstmann写道: If multiple threads modify a plain HashMap,they can destroy the internal structure. Some of the links may go missing,or even go in circles,rendering the data structure unusable. ( Section 6.2.1 ) 我
在 Java 8中,真正不耐烦的Horstmann写道:

If multiple threads modify a plain HashMap,they can destroy the
internal structure. Some of the links may go missing,or even go in
circles,rendering the data structure unusable. (Section 6.2.1)

我可以理解,未同步的并发访问可能会破坏我的数据.如果两个线程都更新相同的值,则可以覆盖另一个.

但为什么以及如何破坏内部存储器结构呢?

解决方法

您正在寻找的答案在 this博文中得到了完美的解释.

如果您仔细阅读它,您将看到竞争条件可能会破坏存储桶中项目之间的指针,从而导致查找变为两个项目之间的无限遍历.

我不确定Java 8的HashMap实现有多少变化,但我怀疑基础知识仍然适用.

我还要补充一点,这个问题不难发现,我实际上已经看到它发生在现实生活系统中!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读