In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail about the generation principle of the JDK7 HashMap ring, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
JDK7 analysis
In JDK7, when we use head insertion to relocate the old table data to the new table, we know that it will travel the loop. The core function transfer generated by the ring is as follows, in which the key part is marked.
Plug in normal circumstances: in the case of concurrency, for example, I have two threads performing put data and capacity expansion operations at the same time, thread 1 only executed Entry next = e.next and then was suspended, while thread 2 finished normal execution, the result figure is as follows: thread 1 then executes the following statement from the original pause: through step-by-step analysis and drawing, you can know that the red part will have a ring. HashMap is not safe in JDK, and ConcurrentHashMap should be used in multithreaded cases. It was used 4 times to find Hash in 7vs87, but only once in 8. 7 = array + linked list, 8 = array + linked list + red-black tree 7 is head insertion, multi-thread is easy to cause ring, and 8 is tail insertion. The expansion of 7 is to relocate all the data, while in 8, the location is unchanged and the old size size is moved to achieve better. 7 is to determine whether to expand capacity and then insert, and 8 is to insert first and then to see whether to expand capacity. HashMap is not thread-safe regardless of 78. Remember to use ConcurrentHashmap in the case of multithreading. ConcurrentHashmap's next article says. common problem
Randomly collected some common HashMap problems, if you understand the HashMap to deal with these should be no problem.
HashMap principle, internal data structure. The general process of put,get,remove in HashMap. The implementation of hash function in HashMap. How to expand HashMap. Why several important parameters of HashMap are set in this way. Why HashMap is not thread-safe and how to replace it. The difference between HashMap in JDK7 and JDK8. Switch between linked list and red-black tree in HashMap. Sowhat1412 asked a question about what the principle of JDK7 HashMap ring generation is to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.