当前位置:网站首页>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
边栏推荐
- CS免杀姿势
- 全新探险者以40万的产品击穿豪华SUV价格壁垒
- Why do I strongly recommend using smart async?
- 请问下,flink cdc监控oracle,我看源码是通过sid方式的,请问怎么改成service
- 美国国防部更“青睐”光量子系统研究路线
- 【Unity入门计划】基本概念(8)-瓦片地图 TileMap 02
- 一文看懂推荐系统:召回01:基于物品的协同过滤(ItemCF),item-based Collaboration Filter的核心思想与推荐过程
- 分享一款免费OPC UA服务器
- AI+BI+可视化,Sugar BI架构深度剖析
- 深入浅出Flask PIN
猜你喜欢
随机推荐
Some optional strategies and usage scenarios for PWA application Service Worker caching
使用Make/CMake编译ARM裸机程序(基于HT32F52352 Cortex-M0+)
托尔斯泰:生活中只有两种不幸
leetcode-268.丢失的数字
How much do you know about the intelligent operation and maintenance service of data warehouse based on DMS?
美国国防部更“青睐”光量子系统研究路线
Small Tools(4) 整合Seata1.5.2分布式事务
常见分布式理论(CAP、BASE)和一致性协议(Gosssip、Raft)
Tolstoy: There are only two misfortunes in life
How to prevent hacking Windows server security Settings
出海季,互联网出海锦囊之本地化
我写了个”不贪吃蛇“小游戏
Research on power flow in DC microgrid based on Newton's method (Matlab code implementation)
一文看懂推荐系统:召回01:基于物品的协同过滤(ItemCF),item-based Collaboration Filter的核心思想与推荐过程
小熊派——无线联网开发
STM32 GPIO LED和蜂鸣器实现【第四天】
下午见!2022京东云数据库新品发布会
spark入门学习-1
参与便有奖,《新程序员》杂志福利来袭!
Why do I strongly recommend using smart async?