什么是悲观锁和乐观锁,举例说明项目中如何实现?
时间: 2024-04-27 14:20:24 浏览: 113
悲观锁和乐观锁都是并发控制的手段。悲观锁是在对记录进行修改前,先尝试为该记录加上排他锁,如果加锁失败则需要等待或抛出异常,成功加锁后可以对记录做修改,事务完成后解锁。悲观锁适用于多写的场景,因为冲突较多,而且会导致上层应用不断进行retry,降低性能。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [什么是乐观锁,什么是悲观锁](https://blog.csdn.net/meimeieee/article/details/109266457)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [MySQL之数据库的乐观锁和悲观锁是什么?怎么实现的?使用场景?](https://blog.csdn.net/weixin_52690231/article/details/124923268)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文