当前位置:网站首页>multithreaded lock
multithreaded lock
2022-07-31 18:33:00 【51CTO】
There are two types of thread locks:内置锁(synchronized)和显式锁(ReentrantLock)
简单对比:
主要相同点:Lock能完成synchronized所实现的所有功能
主要不同点:Lock有比synchronized更精确的线程语义和更好的性能,When many threads are contending for the same lock,使用 ReentrantLock 的总体开支通常要比 synchronized 少得多.
synchronized会自动释放锁,而Lock一定要求程序员手工释放,To prevent forgetting to release the lock,一般在finally从句中释放.
SynchronizedWaiting time cannot be set,So if the waiting resource has been occupied,可能会出现死锁.
ReentrantLockbe more flexible,可以设置等待的时间,如果等待的时间到了,will do other tasks.
更多了解
边栏推荐
- 【Yugong Series】July 2022 Go Teaching Course 020-Array of Go Containers
- Jiuqi ny3p series voice chip replaces the domestic solution KT148A, which is more cost-effective and has a length of 420 seconds
- 【PIMF】OpenHarmony 啃论文俱乐部—盘点开源鸿蒙三方库【3】
- rj45对接头千兆(百兆以太网接口定义)
- Multi-datacenter operation and detection of concurrent writes
- [TypeScript] OOP
- Basics of ResNet: Principles of Residual Blocks
- ThreadLocal
- 手把手教你学会部署Nestjs项目
- 每日练习------随机产生一个1-100之间的整数,看能几次猜中。要求:猜的次数不能超过7次,每次猜完之后都要提示“大了”或者“小了”。
猜你喜欢
How can we improve the real yourself, become an excellent architect?
手把手教你学会部署Nestjs项目
如何识别假爬虫?
自动化测试—web自动化—selenium初识
Three.js入门
useragent在线查找
新型电信“套路”,我爸中招了!
The new telecom "routine", my dad was tricked!
Bika LIMS 开源LIMS集—— SENAITE的使用(检测流程)
Introduction of Jerry voice chip ic toy chip ic_AD14NAD15N full series development
随机推荐
Apache EventMesh 分布式事件驱动多运行时
MySQL---sort and pagination
Last write wins (discards concurrent writes)
Chinese encoding Settings and action methods return values
flyway的快速入门教程
ThreadLocal
使用 Flutter 和 Firebase 制作!计数器应用程序
获取抖音视频详情 API
The server encountered an internal error that prevented it from fulfilling this request的一种解决办法[通俗易懂]
rj45对接头千兆(百兆以太网接口定义)
1161. 最大层内元素和 : 层序遍历运用题
leetcode:6135. 图中的最长环【内向基环树 + 最长环板子 + 时间戳】
中文编码的设置与action方法的返回值
Flex布局详解
GateWay实现负载均衡
Introduction of Jerry voice chip ic toy chip ic_AD14NAD15N full series development
多主复制下处理写冲突(3)-收敛至一致的状态及自定义冲突解决逻辑
并发性,时间和相对性
认识异常 (看完这篇你就懂了)
iNeuOS工业互联网操作系统,设备运维业务和“低代码”表单开发工具