Differences between read locks and write locks

Source: Internet
Author: User

Read lock: Read is not mutually exclusive
Write lock: exclusive

Readwritelock
Synchronized is exclusive.

1. In the Java concurrent library, reetrantreadwritelock implements the readwritelock interface and adds the reentrant feature.
2. reetrantreadwritelock: the efficiency of the read/write lock is significantly higher than that of the synchronized keyword.
3. In the implementation of the reetrantreadwritelock read/write lock, the read lock uses the sharing mode; the write lock uses the exclusive mode. In other words, the read lock can be held by multiple threads when no write lock is available, and the write lock is exclusive.
4. in the implementation of the reetrantreadwritelock read/write lock, it should be noted that when there is a read lock, the write lock cannot be obtained; and when there is a write lock, in addition to the thread that obtains the write lock, the read lock can be obtained, other threads cannot obtain the read lock.

Differences between read locks and write locks

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.