Java program consumes CPU 100% lookup method

Source: Internet
Author: User

cause of the problem: because the HashMap is non-thread-safe, it causes a dead loop during multithreaded access.

To find the problem method:
1.

Java code
    1. Top


Find the CPU-intensive process number such as: 27377

2.

Java code
    1. Top-p 27377-h


Find out all the threads under this process, and then find the CPU thread number that consumes the most: 27433

3.

Java code
    1. Python hex (27433)


Converts a decimal number to a 16 binary such as: 0x6b29

4.

Java code
    1. Jstack 27377 >cpu.log


Print the Java stack information for this process number to a file

5.

Java code
    1. grep 0x6bz8 Cpu.log


Look at the threads in the Java stack, nid:
"FoundationTaskExecutor-2" prio=10 tid=0x00007f064c041000 nid=0x6b28 runnable [0x00007f069f5da000]

6.

Java code
    1. Vim Cpu.log


Find the contents of nid=0x6b28 such as:

Java code
    1. "FoundationTaskExecutor-2" prio=tid=0x00007f064c041000 nid= 0x6b28runnable [0x00007f069f5da000]
    2. Java.lang.Thread.State:RUNNABLE
    3. At Java.util.HashMap.get (Hashmap.java:)
    4. At *********************************** (Wareserviceimpl.java: +)
    5. At *********************************** (Mid2foundationtask.java:127)
    6. At *********************************** (Mid2foundationtask.java:)
    7. At *********************************** $FoundationThreadImpl. Run (Mid2foundationtask.java:
    8. At Java.util.concurrent.ThreadPoolExecutor.runWorker (Threadpoolexecutor.java:1110)
    9. At Java.util.concurrent.threadpoolexecutor$worker.run (Threadpoolexecutor.java:603)
    10. At Java.lang.Thread.run (Thread.java:722)

Java program consumes CPU 100% lookup method

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.