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.