Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that HashMap will still produce an endless loop in JDK8?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to solve the problem that HashMap will still have an endless cycle in JDK8. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Have you ever heard of the problem of expanding the dead loop that HashMap has solved after JDK8? although HashMap still says that threads are unsafe, it will not cause the server load to soar.

However, this is not the case. Has the teenager ever known a scene of red and black trees forming a ring, = v =

Today, when I checked the monitoring, I found that the load of a certain machine soared.

Feel that something is wrong, ssh Dafa login machine, top,top-Hp,jstack, JMap four-click to save the stack, cpu uses the highest thread, memory information ready for analysis.

First look at the thread stack information that uses the most cpu

Cat stack | grep-I 34670-C10-- color

Damn it, HashMap, guess it's probably a dead loop, but the JDK8 we used solved the problem of expanding the dead loop through stack-closed linked list replacement in 8. Confused, read on.

According to the stack information, the root method is the problem. Click on the HashMap source code.

Well, the load is soaring high, and the code has a for statement. I think it's bound to be a dead loop. depending on the code, it is only possible that the parents of two red-black tree nodes refer to each other to make it impossible to get out of this for statement.

However, this is all my guess. I have no proof. And it takes a lot of time for me to chase the code of the red-black tree, and I need to quickly verify my guess.

I used dump to get down the heap memory information, and I generated the memory information page of html through the jhat command.

Then enter http://localhost:7000 to view

I first find the object in the business code that holds this HashMap, and then click in to query the internal information.

Because the data is in the table, click the Table field to view its contents

There is only one TreeNode node in table, which must have become a red-black tree.

Click in to check.

Click the parent field information

The Parent references of the two TreeNode nodes, 0x72745d828 and 0x72745d7b8, are each other.

This is how to solve the problem that HashMap still has an endless loop in JDK8 shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report