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 use jstack to analyze an online memory overflow problem

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

How to use jstack to analyze an online memory overflow problem, I believe that many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Recently, there is a business activity in the company, and the traffic has increased dramatically. The data skyrocketed more than 10 times, and the system could not be supported, which led to the program memory overflow and system downtime. Check the log and find that there is a memory overflow exception. Today I will share with you how to use the jstack command to troubleshoot and locate the exception code in the java program.

In order to clarify the use of jstack and the problems caused by our system, I simplified the online problem to the following code:

When you run the above code, you might expect that it will never have a problem. After all, the built-in cache scheme will only increase to 10000 elements, and then it won't be added any more. All the key has already appeared in HashMap. Just because you lack a flow chart of HashMap! What is the meaning of HashMap? However, this is not the case. The element will continue to grow because the Key class only implements the hashCode () method and does not override the equals () method (deep interpretation of equals (), = =, hashCode () in Java).

After running this program, we found that it didn't take too long, and the program reported a memory overflow. Turn on task management, in this case, find the java process ID.

If it is convenient, you can also use ProcessExplorer to find the java process with ID number 7064. The attribute information of the process ID of 7064 finds the thread information of CPU utilization in the Thread tag, and the TID is 6120 (decimal).

Convert a thread with high CPU utilization, ID 6120 (decimal) to 0x17E8 (hexadecimal)

Use jstack to view thread information for process 7064. Find the thread whose thread number is 0x17E8. Command:

According to the line number of the prompt, we locate the relevant code. Through the analysis, it is found that the memory overflow is caused by map.

The solution is simple, as long as you add an equals method as in the following example. But you must have spent a lot of valuable brain cells before you find out what the problem is.

The jstack command is very useful and is a stack trace tool that comes with the java virtual machine.

After reading the above, do you know how to use jstack to analyze an online memory overflow problem? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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

Servers

Wechat

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

12
Report