The java program consumes 100% of the cpu to find the method

Source: http://kevin1.iteye.com/blog/1532716 Cause
of the problem: Since HashMap is not thread-safe, it will cause an infinite loop when accessed by multiple threads.

Find the problem method:
1.
Java code favorite code

    top 


to find out the process number that consumes the most CPU, such as: 27377

2.
Java code favorite code

    top -p 27377 -H 


Find all threads under this process, and then find the most cpu-consuming thread Number such as: 27433

3.
Java code collection code

    python hex(27433)  


converts the decimal number to hexadecimal such as: 0x6b29

4.
Java code collection code

    jstack 27377 >cpu.log prints 


the Java stack information of this process number to a file

5.
Java code Collection code

    grep 0x6bz8 cpu.log to 


view the thread nid in the java stack such as:
"foundationTaskExecutor-2" prio=10 tid=0x00007f064c041000 nid=0x6b28 runnable [0x00007f069f5da000]

6.
Java code Favorite code

    vim cpu.log to 


find nid=0x6b28 content such as:
Java code Favorite code

    "foundationTaskExecutor-2" prio=10 tid=0x00007f064c041000 nid=0x6b28 runnable [0x00007f069f5da000] 
       java.lang.Thread.State: RUNNABLE 
            at java. util.HashMap.get(HashMap.java:320) 
            at ************************************(WareServiceImpl .java:64) 
            at ************************************(Mid2FoundationTask.java:127) 
            at * ************************************(Mid2FoundationTask.java:27) 
            at ******** ****************************$FoundationThreadImpl.run(Mid2FoundationTask.java:86) 
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
            at java.lang.Thread.run(Thread.java:722) 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326928150&siteId=291194637