Using Jstack to analyze high CPU consumption issues

Source: Internet
Author: User

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 9712 S 3.3 4.9 12:03.24 java
5284 co_ad 0 3028m 2.5g 9432 S 1.0 16.3 6629:44 java
21994 MySQL 0 449m 88m 5072 S 1.0 0.6 67582:38 mysqld
8657 Co_sparr 0 2678m 892m 9220 S 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
Enter Top-p 21125 First, and then press SHIFT+H. This means that only 21125 of the process is viewed, and the thread is displayed.
21233 co_ad2 0 1807m 630m 9492 S 1.3 4.0 0:05.12 Java
20503 co_ad2_s 0 1360m 560m 9176 s 0.3 3.6 0:46.72 Java
21134 co_ad2 0 1807m 630m 9492 S 0.3 4.0 0:00.72 Java
22673 co_ad2 0 1807m 630m 9492 S 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
    1. 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
    1. "http-8081-11" daemon prio=tid=0x00002aab049a1800 nid=0x52f1 in object.wait () [0x0000000042c75000]
    2. Java.lang.Thread.State:WAITING (on object monitor)
    3. At java.lang.Object.wait (Native Method)
    4. At Java.lang.Object.wait (Object.java:485)
    5. At Org.apache.tomcat.util.net.jioendpoint$worker.await (Jioendpoint.java:416)


You might be able to locate the offending code at once.

Using Jstack to analyze high CPU consumption issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.