How Java looks at deadlocks

Source: Internet
Author: User

So how do we know it must be a deadlock? There are two ways.

1> use the JDK to our tool jconsole, which can be opened by opening cmd and typing jconsole.

1) Connect to the process you want to view.

2) Open the Threads tab, then click "Detect Deadlock" in the lower left corner

3) Jconsole will show us the thread that caused the deadlock in this thread, click to select to see the details:

From which we can see:

① thread Thread-1, from the state can be seen, it wants to apply for paper this resource, but this resource has been Thread-0 owned, so it is blocked.

② thread Thread-0, from the state can be seen, it wants to apply for pen this resource, but this resource has been Thread-1 owned, so it is blocked.

Thread-1 has been waiting for paper resources, and thread--has been waiting for a pen resource, so the two threads are so deadlocked, resulting in a deadlock.

2> Direct use of commands from the JVM

1) first through the JPS command to see the Java process needs to see the vmid, we want to see the process Testdeadlock vmid number is 7412;

    

2) then use Jstack to view the stack situation in the process, enter Jstack-l 7412 in cmd, and move to the bottom of the output information to get:

    

At this point, I believe everyone will look at it, specifically do not say, according to the output, find the code of the problem, start debugging solution can be.

How Java looks at deadlocks

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.