Analyze the reasons why java occupies a large amount of CPU resources in CentOS
1. Use the top command to find the Java Process PID. Here, the PID is 16871.
2. After finding the process, you need to locate the specific thread or code. First, the thread list is displayed and sorted by the threads with high CPU usage:
Ps-mp 16871-o THREAD, tid, time | sort-rn
The result is as follows:
USER % CPU PRI SCNT WCHAN USER SYSTEM TID TIME
Root 90.5 19---9521 01:16:48
Root 90.1 19---952201: 02: 16
We found the thread with the highest time consumption of 9521, and it took more than one hour to occupy the CPU.
Convert the required thread ID to the hexadecimal format:
Printf "% xn" 9521
2531
Finally, run the jvm command to print the stack information of the thread:
Jstack 16871 | grep 2531-A 30
In this way, we can find the code that occupies java and cpu resources. Next we have to analyze the reason for code execution.