Java – how multithreading destroys the internal structure of HashMap

In Java 8, the really impatient Horstmann wrote:

I can understand that unsynchronized concurrent access may destroy my data If both threads update the same value, the other can be overwritten

But why and how to destroy the internal memory structure?

Solution

The answer you are looking for is perfectly explained in this blog post

If you read it carefully, you will see that the race condition may destroy the pointer between items in the bucket, resulting in an infinite traversal between two items

I'm not sure how many changes have been made to the HashMap implementation of Java 8, but I doubt the basics still apply

I would also like to add that this problem is not difficult to find. I have actually seen it happen in the real-life system!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>