Java: Find the thread that consumes the most CPU resources (how to)

Source: Internet
Author: User

Here is a summary of the steps to find the thread resource consumption problem for Linux, Sun (Oracle) JDK, in Linux, when the Java process is found to occupy a high CPU resource, and want to further find out which Java thread is consuming CPU resources, Follow these steps to find:

  1. Use the top command to find the Java process ID that consumes resources, such as:
  2. As shown, the process ID of Java is ' 12377 ', and then all threads in the process are monitored separately with the top command:?
    1 top-p 12377 -H


  3. As shown in Linux, all Java internal threads actually correspond to a process ID, which means that the Sun JVM on Linux maps threads in Java programs to operating system processes, and we see that the process ID that consumes the most CPU resources is ' 15417 ', This process ID corresponds to the ' Nid ' (' n ' stands for ' native ') in the Java thread information;
  4. To find out exactly which specific code occupies so many resources, first use Jstack to play the current stack of information into a file, such as Stack.log:?
    1 jstack 12377 > stack.log

    Then use the ' jtgrep ' script to grab the Java thread with the process number ' 15417 ' in Stack.log:

    ?
    1 jtgrep 15417 stack.log

Among them, ' Jtgrep ' is a shell script that he writes casually:

?
1234 #!/bin/shnid=`python -c "print hex($1)"`grep-i $nid $2

The truth is simple, is to convert ' 15417 ' into 16, directly grep stack.log, you can see that the grep out of the thread's nid=0x3c39, just 15417 of the 16 binary representation.

Article Source: http://wenyue.me/blog/382

Java: Find the thread that consumes the most CPU resources (how to)

Related Article

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.