java hashmap 多线程,java – 为什么我们要在多线程环境中使用HashMap?

今天我正在阅读HashMap如何在

java中工作.我遇到了一个博客,我直接引用了博客的文章.我在Stackoverflow上看过

this篇文章.仍然

我想知道细节.

So the answer is Yes there is potential race condition exists while

resizing HashMap in Java, if two thread at the same time found that

now HashMap needs resizing and they both try to resizing. on the

process of resizing of HashMap in Java , the element in bucket which

is stored in linked list get reversed in order during there migration

to new bucket because java HashMap doesn’t append the new element at

tail instead it append new element at head to avoid tail traversing.

If race condition happens then you will end up with an infinite loop.

它指出,由于HashMap在调整HashMap的大小调整期间不是线程安全的

情况可能发生.我甚至在办公室项目中看到过,人们都在广泛使用

HashMaps知道它们不是线程安全的.如果它不是线程安全的,我们为什么要使用HashMap

然后?是开发人员缺乏知识,因为他们可能不了解ConcurrentHashMap等结构或其他原因.任何人都可以解释这个难题.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值