当前位置:网站首页>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.


更多了解
边栏推荐
- Introduction of Jerry voice chip ic toy chip ic_AD14NAD15N full series development
- MySQL---聚合函数
- useragent在线查找
- AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)
- Apache EventMesh 分布式事件驱动多运行时
- leetcode 665. Non-decreasing Array 非递减数列(中等)
- Jiuqi ny3p series voice chip replaces the domestic solution KT148A, which is more cost-effective and has a length of 420 seconds
- Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
- 如何才能真正的提高自己,成为一名出色的架构师?
- 淘宝/天猫获得淘口令真实url API
猜你喜欢
随机推荐
多主复制下处理写冲突(3)-收敛至一致的状态及自定义冲突解决逻辑
Istio介绍
杰理语音芯片ic玩具芯片ic的介绍_AD14NAD15N全系列开发
【AcWing】第 62 场周赛 【2022.07.30】
Handling write conflicts under multi-master replication (3) - Convergence to a consistent state and custom conflict resolution logic
[Source code analysis] BeanFactory and FactoryBean
Apache EventMesh 分布式事件驱动多运行时
Chinese encoding Settings and action methods return values
几款永久免费内网穿透,好用且简单(内网穿透教程)
ResNet的基础:残差块的原理
mysql的备份表的几种方法
【愚公系列】2022年07月 Go教学课程 021-Go容器之切片操作
MySQL---Create and manage databases and data tables
【Yugong Series】July 2022 Go Teaching Course 021-Slicing Operation of Go Containers
MySQL---sort and pagination
无主复制系统(1)-节点故障时写DB
iNeuOS工业互联网操作系统,设备运维业务和“低代码”表单开发工具
移动web开发02
35 MySQL interview questions and diagrams, this is also easy to understand
C# 之 扑克游戏 -- 21点规则介绍和代码实现








