? 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