当前位置:网站首页>MySQL optimistic lock
MySQL optimistic lock
2022-07-21 09:24:00 【Leon_ Jinhai_ Sun】
Optimistic locking holds that concurrent operations on the same data will not always occur , It's a small probability event , You don't have to lock the data every time , But in the process of updating, we will judge whether other people have updated this data during this period , That is to say Do not use the locking mechanism of the database itself , But through Program to achieve . On procedure , We can use Version number mechanism perhaps CAS Mechanism Realization . Optimistic lock is suitable for multi read applications , This can improve throughput . stay Java in java.util.concurrent.atomic The atomic variable class under the package is an implementation method that uses optimistic locking :CAS Realized .
1. Optimistic lock version number mechanism : Design a... In the table Version field version , The first time I read it , Will get version Value of field . Then update or delete the data , Will execute UPDATE ... SET version=version+1 WHERE version=version . At this time, if a transaction has changed this data , The modification will not succeed .
2. The timestamp mechanism of optimistic lock : Timestamp is the same as the version number mechanism , It's also when the update is submitted , Compare the timestamp of the current data with that obtained before the update , If both are consistent, the update is successful , Otherwise it's a version conflict . As you can see, optimistic lock is the programmer's permission to control the concurrent operation of data , Basically by adding a stamp to the data row ( Version number or time stamp ), So as to prove whether the current data is up-to-date .
边栏推荐
猜你喜欢
New research of Stanford and meta AI: Data pruning is more important than we think on the road to AgI
The IPO of minshi group was terminated: Qin ronghua, who had planned to raise 6.5 billion yuan, was punished by the court
VB. Net plug-in development case
什么是IFTMCS指示合同状态报文?
(作业)C语言做题:内存函数memmove、memcpy的模拟
可观测性提升软件工程质量,观测云出席2022 QECon全球软件质量&效能大会
游戏合作伙伴专题:BreederDAO 与 MonkeyLeague 的合作拉开序幕
兼容认证|青云QKCP与观测云完成产品兼容性互认证,携手打造云原生可观测能力
WireShark 简介和抓包原理及过程
陈丹青版画作品首次元宇宙拍卖明日揭幕!
随机推荐
SAP BTP 上 Roles,Roles collection 和 Scopes 的关联关系
C language: preprocessing
安装 scoop和lux (原annie)
MySQL显式锁
菜鸟教程之工具使用——IDEA 查看子类(实现类)类图
百家云与美股上市公司富维薄膜达成合并协议:作价5.2亿美元
Kotlin 函数魔法 – lambda 表达式
百度工程师眼中的云原生可观测性追踪技术
7.16 - 每日一题 - 408
LCD断码屏显示应用框架
C语言:预处理
我国科学家在高安全量子密钥分发网络方面取得新进展
兼容认证|青云QKCP与观测云完成产品兼容性互认证,携手打造云原生可观测能力
SAP UI5 System Test 的工具之一:uiveri5
batchInsert避免插入重复数据ignor
【Unity基础知识】基础游戏单位GameObject中常用的属性和API
How to cut out only the people in the gait contour of the human body
Unity Slider滑动条开发
MySQL password modification (teach you by hand)
7.14 - 每日一题 - 408