当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
开源一夏 | 阿里云物联网平台之极速体验
Introduction to spark learning - 1
AWS中国区SDN Connector
小熊派——无线联网开发
请问下阿里云全托管flink能执行两条flink sql命令么?
Ruoyi Ruoyi framework @DataScope annotation use and some problems encountered
深入浅出Flask PIN
Research on power flow in DC microgrid based on Newton's method (Matlab code implementation)
Go Go 简单的很,标准库之 fmt 包的一键入门
生态剧变,电子签名SaaS模式迎来新突破,网络效应加速到来
TCP 可靠吗?为什么?
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
我在滴滴做开源
Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)
Interpretation of the 2021 Cost of Data Breach Report
一文看懂推荐系统:召回02:Swing 模型,和itemCF很相似,区别在于计算相似度的方法不一样
window.open does not show favicon.icon
PWA 应用 Service Worker 缓存的一些可选策略和使用场景
Small Tools (4) integrated Seata1.5.2 distributed transactions
Introduction to the advantages of the new generation mesh network protocol T-Mesh wireless communication technology