今天我正在阅读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等结构或其他原因.任何人都可以解释这个难题.