java occupies the highest cpu thread stack information

jstack finds out the thread stack information that occupies the highest cpu

package com.example.demo;
public class Math {
    public static final int initData = 666;
    public int compute() {
        //
        int a = 1;
        int b = 2;
        int c = (a + b) * 10;
        return c;
    }
    public static void main(String[] args) {
        Math math = new Math();
        while (true) {
            math.compute();
        }
    }
}

1. Use the top command or top -p process number to specify the memory status of your java process, and pid is your java process number, such as 19663

image.png

2. Press H to get the memory status of each thread

image.png

3. Find the thread tid with the highest memory and CPU usage, such as 19664

4. Convert to hexadecimal to get 0x4cd0, which is the hexadecimal representation of the thread id

5. Execute jstack 19663|grep -A 10 4cd0, and get the last 10 lines of the thread 4cd0 in the thread stack information. From the stack, you can find the calling method that causes the CPU to soar

image.png

6. Check the corresponding stack information to find out the code that may have problems

Guess you like

Origin blog.csdn.net/robinhunan/article/details/131008542