Recently, I encountered a Java application that caused the server CPU usage to be too high. Finally, I checked the problem because the Tomcat process was not killed when the application was redeployed under Tomcat. As a result, the lock in the database connection pool process of the application could not be released, and the CPU usage was too high due to an infinite loop. Detailed reasons will not do a detailed analysis, mainly to share the process of troubleshooting problems.

Run the top command to query the CPU usage of the service

As you can see, 31737 is a very CPU intensive process

Run the top-hp 31737 command to query the resource usage of each thread in process 31737

top -Hp 31737
Copy the code

Run the top-hp 31737 command to query the resource usage of each thread in process 31737

Because the screenshot was lost at that time, the command top-hp 31737 shows that thread 5322 occupies too much CPU

Convert the thread ID to hexadecimal using printf “%x\n” 5322

printf "%x\n" 5322
Copy the code

Because the local thread ID nID is expressed in hexadecimal when printing the thread stack, use this command to convert the thread ID to hexadecimal

Run the jstack command to print the stack information

jstack 31737 | grep -10 14ca
Copy the code

Use jstack 31737 | grep – 10 of 14 ca print 31737 stack information, and look for local thread identifier for 14 ca thread stack information

As shown, thread state is TIMED_WAITING, object waiting, view the source code

Find the cause of the problem is not to do a detailed analysis, here is mainly to share the process of problem investigation Baidu there is a god answered well, link here, interested can go to have a lookStackoverflow.com/questions/6… The cause is that the Tomcat process is not killed during application redeployment. As a result, the lock in the database connection pool process cannot be released

This troubleshooting process is to share with you here, welcome everyone to communicate, point out some mistakes in the article, let me deepen my understanding, I wish you no bugs, thank you!