Article directory
When the CPU of the Java service production environment suddenly increases and the log query fails, you can locate the problem by using the JVM debugging tool.
ideas
Locate the java service process -> locate the java thread -> locate the code block
1. Locate the java service process
A server may have multiple java services. Use the top
command to check which service has the highest CPU usage. Remember the PID number with high CPU usage.
2. Locate the thread id
There are many threads executing in each java service, ps H -eo pid,tid,%cpu --sort=%cpu |grep [PID]
which thread has higher CPU usage can be located by
[root@]# ps H -eo pid,tid,%cpu --sort=%cpu |grep 20443
20443 22263 0.0
20443 20469 0.3
20443 20451 0.4
20443 20466 0.6
20443 20468 0.6
20443 20467 50.0
As shown in the figure above, you can see that 20467
the CPU usage of the thread is high, and you can check which piece of code is using the most.
3. Locate the code block
The jstack [PID]
execution state of the thread can be displayed as shown in the figure below, but it is messy, and it is searched by 20467
converting to 16进制
.
Search for the corresponding thread information, and you can intuitively see the code exception information.
It can be tested through a while loop in springboot.
@GetMapping ("/while")
public void while1(){
log.info ("while!~~~~~~~~~");
while (true){
}
}