One
using top and Jstack to find thread errors
We use the jstack from the JDK to analyze it. When Linux CPU is consumed by Java programs, the following process might help you:
1.top Find out which process consumes a high CPU
21125 co_ad2 0 1817m 776m 9712S 3.3 4.9 12:03.24java
5284co_ad 0 3028m 2.5g 9432S 1.0 16.3 6629:44java
21994mysql 0 449m 88m 5072 S 1.0 0.6 67582:38mysqld
8657 Co_sparr 0 2678m 892m 9220S 0.3 5.7 103:06.13 Java
Here we analyze 21125 of this Java process.
2.top shift+h Find out which thread consumes a high CPU
First enter top, then press Shift+h
21233 co_ad2 0 1807m 630m 9492S 1.3 4.0 0:05.12java
20503 co_ad2_s 0 1360m 560m 9176S 0.3 3.6 0:46.72java
21134 co_ad2 0 1807m 630m 9492S 0.3 4.0 0:00.72java
22673 co_ad2 0 1807m 630m 9492S 0.3 4.0 0:03.12 Java
Here we analyze 21233 of this thread, and note that this thread is part of the 21125 process.
3.jstack find information for this thread
Jstack [Process]|grep-a 10 [thread 16]
That
Java code
- Jstack 21125|grep-a 52F1
-A 10 means finding the following 10 rows of the row. 21233 Convert the calculator to 16 binary 52f1, note that the letter is lowercase.
Results:
Java code
- "http-8081-11" daemon prio=10 tid=0x00002aab049a1800 NID=0X52BB in object.wait () [0x0000000042c75000]
- Java.lang.Thread.State:WAITING (on object monitor)
- At java.lang.Object.wait (Native Method)
- At Java.lang.Object.wait (object.java:485)
- At Org.apache.tomcat.util.net.jioendpoint$worker.await (jioendpoint.java:416)
You might be able to locate the offending code at once.
Two
Jstack (view threads), Jmap (view memory), and Jstat (profiling) commands
Specific view: http://guafei.iteye.com/blog/1815222
Linux thread error lookup, with threading Analysis command