Java Readwritelock Lock

Source: Internet
Author: User

? once the synchronized adornment is added to the method of the object, only one thread can access the synchronized decorated method at any time. Suppose that a data object has a write method and a read method, in order to ensure the security of data in multi-threaded environment, it is necessary to add the synchronized synchronization block to the object's reading and writing methods. When any thread is written, other threads cannot read and change the data, and other threads cannot read or write while the threads are reading. This way, when the write operation is much larger than the read operation, the problem is small, and when the read is far greater than the write, it can cause a performance bottleneck, because the read operation is possible at the same time, and the lock operation restricts the concurrent reading of the data.

in multithreaded development, there is often a situation where we want to read and write separate. is to read this action, can have a number of lines Chengtong at the same time to read this resource, but for writing this action, can only have one thread to operate, and at the same time, when there is a write thread in the operation of this source of capital, Other read threads are not able to operate this resource, so that greatly play the characteristics of multi-threading, can be a good multi-threaded ability to play out.

Readwritelock resolved : When the write operation, other threads cannot read or write data, and when read operation, other threads cannot write data, but can read the data

Java Readwritelock Lock

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.