Graphical source of Java Lock Acquisition and release (AQS) Chapter

Source: Internet
Author: User

Take exclusive unfair lock as an example, through 5 threads to compete for Reentrantlock process, plot Reentrantlock source code realization, understand the work flow of display lock.

There is only one thread that gets the lock at any moment, the thread that does not get the lock is packaged as a node, and the node is then placed in the synchronization queue from the end of the queue via the CAS spin.

Increase the tail node why use CAS because there will be multiple threads competing for tail nodes.

The above is the process of thread competition and all the things that need to be done after the competition fails.

The above is the whole process of thread acquisition and release lock, which can be summarized by the following flowchart.

In addition, the above source code are from jdk1.8, this article as a sort of ideas, only a summary of the key parts, detailed process please readers follow the idea of self-reading source code, English clearance is one of the necessary skills to read, or can not read the comments really hurt the egg. The important thing to say three times, English must be better!

English must be better! English must be better!

Graphical source of Java Lock Acquisition and release (AQS) Chapter

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.