Analysis on single CPU usage of java application linux service 100%, javalinux

Source: Internet
Author: User
Tags jconsole

Analysis on single CPU usage of java application linux service 100%, javalinux

In the previous project process, performance tests were performed on the linux server after the project was completed. When the Service ran, it was found that the cpu usage was very strange. The java application ran a single cpu Full, other cpu usage rate is 0%.

 

When I first encountered this problem, I immediately used the jconsole tool that comes with java for analysis. For details about how to use the remote jconsole tool, refer to my other blog, after the analysis results, only a lot of es client objects are created, and no exception is found for others.

I will block this part of the code, and then start the service to find that the problem still exists, it means that it is not the es client object that consumes cpu.

As a result, I thought of using java's jvisualvm tool and performing an endless loop and Deadlock Detection on the code. No problems were found.

Finally, I used the jstack tool to analyze the threads that are currently using the cpu. For details about how to use jstack, see worker.

Final analysis result:

 

Check the results. We can find that the init method of the ContentManager class is consistent in execution, and finally find the code,

It is found that the Code contains a while (true) code, which was originally intended for decoupling a Consumer Code. Now it seems that such writing leads to an endless loop and cannot exit, therefore, the single-core cpu utilization rate reaches 100%.

Here, we can find the cause of the Single-core cpu utilization of 100%, and the rest is to optimize this code.

Conclusion:

After consulting the company's old employees and their own analysis, the conclusion is that if there is an endless loop in the code, it will cause a high utilization of Single-core CPU.

Therefore, when using the while (true) code in the future, you must note that it will cause an endless loop.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.