当前位置:网站首页>Detailed explanation of ReentrantReadWriteLock
Detailed explanation of ReentrantReadWriteLock
2022-08-03 16:09:00 【jerry_dyy】
Introduction:
All operations in ReentrantLock are mutually exclusive. In reality, there is a scenario where reading is very frequent, but writing is very little.In such a scenario, if the read and the read are not mutually exclusive, then the concurrency efficiency can be greatly improved, so the corresponding ReentrantLReadWriteLock appears.ReentrantReadWriteLock can do: read-read sharing, read-write mutual exclusion, and write-write mutual exclusion.
The implementation method is: two locks are encapsulated internally, one exclusive lock and one shared lock, between the threads that acquire the exclusive lockTo be synchronized; the threads between acquiring the exclusive lock and acquiring the shared lock are also synchronized; the threads acquiring the shared lock do not need to be synchronized.
Example of use:
public class ReentrantReadWriteLockDemo {private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();private ReentrantReadWriteLock.ReadLock readLock = rwLock.readLock();private ReentrantRead边栏推荐
猜你喜欢

Neural networks, cool?

神经网络,凉了?

ECCV 2022 | 基于关系查询的时序动作检测方法

《安富莱嵌入式周报》第276期:2022.07.25--2022.07.31

QT QT 】 【 to have developed a good program for packaging into a dynamic library

深入浅出Flask PIN

How much do you know about the intelligent operation and maintenance service of data warehouse based on DMS?

Awesome!Coroutines are finally here!Thread is about to be in the past

常见分布式理论(CAP、BASE)和一致性协议(Gosssip、Raft)

甲方不让用开源【监控软件】?大不了我自己写一个
随机推荐
Daily practice------There are 10 numbers that are required to be output from large to small by selection method
【Unity入门计划】基本概念(6)-精灵渲染器 Sprite Renderer
爬虫注意
泰山OFFICE技术讲座:文字边框高度研究
MATLAB gcf图窗保存图像,黑色背景/透明背景
【QT】Qt项目demo:数据在ui界面上显示,鼠标双击可弹窗显示具体信息
LyScript 验证PE程序开启的保护
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
人脸识别损失函数的汇总 | Pytorch版本实现
一文看懂推荐系统:召回02:Swing 模型,和itemCF很相似,区别在于计算相似度的方法不一样
[Code Hoof Set Novice Village 600 Questions] Define a function as a macro
window.open不显示favicon.icon
Basic knowledge points in js - events
深入浅出Flask PIN
ruoyi若依框架@DataScope注解使用以及碰到的一些问题
【深度学习】今日bug(8月2)
5 v 8.4 v1A charging current charging management IC
Fortinet产品导入AWS AMI操作文档
Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)
劲爆!协程终于来了!线程即将是过去式