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