当前位置:网站首页>事务的本质和死锁的原理
事务的本质和死锁的原理
2020-11-06 21:35:00 【程序猿欧文】
仅以MySQL和spring为例,,本文不介绍事务和锁的概念。
本文使用伪代码表示方法代码,仅仅表达方法的意义及事务注解
〇、事务的形状
在我心中,事务一直是这个样子的
x轴是上锁的资源,y轴是消耗的时间,
事务方块随着时间的流逝向下移动,
当碰触x轴时加锁,越过x轴时解锁
上图是对于方法a的事务形状,我起名【 事务方块】,很抱歉我不会做动图,本文以动图来表达最佳。
@Transactional
function a(){
对A表修改,耗时五秒
}
一、多事务
当一个方法调用多个被事务注解的子方法时情况是
上图是对于方法abc调用时,a方法、b方法、c方法的事务形状function abc(){
this.a(){}
this.c(){}
}
@Transactional
function a(){
对A表修改,耗时五秒
}
@Transactional
function b(){
对B表修改,耗时五秒
}
@Transactional
function c(){
对C表修改,耗时五秒
}
其中abc方法开始执行时,执行到a方法,锁定a表,当a方法结束b方法开始时,a表解锁,b表锁定,当b方法结束c方法开始时,b表解锁c表锁定。
相当于下图的三个事务方块联合且位置锁定一起下落,总运行时间15秒
如果并发请求两次abc方法则事务方块如下图
其中a表会先被请求1锁定5秒后解锁,再被请求2锁定5秒,
其中b表也会先被请求1锁定5秒后解锁,再被请求2锁定5秒,
其中c表也会先被请求1锁定5秒后解锁,再被请求2锁定5秒,
而请求1在解锁表a后紧接着又锁定了表b五秒,同时表a再被请求2锁定5秒
依次类推,请求2都在请求1解锁对应的表之后,锁定该表,
那么总运行时间20秒
二、大事务@Transactional
function abc(){
this.a(){}
this.b(){}
this.c(){}
}
funct.........
版权声明
本文为[程序猿欧文]所创,转载请带上原文链接,感谢
https://my.oschina.net/mikeowen/blog/4553869
边栏推荐
- DRF JWT authentication module and self customization
- 視覺滾動[反差美]
- Markdown tricks
- hdu3974 Assign the task線段樹 dfs序
- Introduction to the structure of PDF417 bar code system
- Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
- What are the criteria for selecting a cluster server?
- 【:: 是什么语法?】
- Azure data factory (3) integrate azure Devops to realize CI / CD
- It's easy to operate. ThreadLocal can also be used as a cache
猜你喜欢
What are manufacturing and new automation technologies?
事件监听问题
每个大火的“线上狼人杀”平台,都离不开这个新功能
It's time for your financial report to change to a more advanced style -- financial analysis cockpit
Isn't data product just a report? absolutely wrong! There are university questions in this category
【ElasticSearch搜索引擎】
有了这个神器,快速告别垃圾短信邮件
A course on word embedding
Construction of encoder decoder model with keras LSTM
美团内部讲座|周烜:华东师范大学的数据库系统研究
随机推荐
With the advent of tensorflow 2.0, can pytoch still shake the status of big brother?
Share with Lianyun: is IPFs / filecoin worth investing in?
有了这个神器,快速告别垃圾短信邮件
Elasticsearch Part 6: aggregate statistical query
From overseas to China, rancher wants to do research on container cloud market
Building a new generation cloud native data lake with iceberg on kubernetes
一部完整的游戏,需要制作哪些音乐?
大会倒计时|2020 PostgreSQL亚洲大会-中文分论坛议程安排
WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
前端未來趨勢之原生API:Web Components
Basic principle and application of iptables
游戏主题音乐对游戏的作用
面试官: ShardingSphere 学一下吧
(2) ASP.NET Core3.1 Ocelot routing
Outsourcing is really difficult. As an outsourcer, I can't help sighing.
华为Mate 40 系列搭载HMS有什么亮点?
It's easy to operate. ThreadLocal can also be used as a cache
【應用程式見解 Application Insights】Application Insights 使用 Application Maps 構建請求鏈路檢視
Simple summary of front end modularization
What course of artificial intelligence? Will it replace human work?