当前位置:网站首页>事务的本质和死锁的原理
事务的本质和死锁的原理
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
边栏推荐
- 新建一个空文件占用多少磁盘空间?
- It is really necessary to build a distributed ID generation service
- Interpretation of Cocos creator source code: engine start and main loop
- html+vue.js 實現分頁可相容IE
- 如何对数据库账号权限进行精细化管理?
- Digital city responds to relevant national policies and vigorously develops the construction of digital twin platform
- Discussion on the development practice of aspnetcore, a cross platform framework
- With the advent of tensorflow 2.0, can pytoch still shake the status of big brother?
- Get twice the result with half the effort: automation without cabinet
- JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
猜你喜欢
How to turn data into assets? Attracting data scientists
如何在终端启动Coda 2中隐藏的首选项?
华为Mate 40 系列搭载HMS有什么亮点?
The importance of big data application is reflected in all aspects
Flink的DataSource三部曲之一:直接API
检测证书过期脚本
MeterSphere开发者手册
Staying up late summarizes the key points of report automation, data visualization and mining, which is different from what you think
Behind the record breaking Q2 revenue of Alibaba cloud, the cloud opening mode is reshaping
JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
随机推荐
With the advent of tensorflow 2.0, can pytoch still shake the status of big brother?
Get twice the result with half the effort: automation without cabinet
解决 WPF 绑定集合后数据变动界面却不更新的问题
Outsourcing is really difficult. As an outsourcer, I can't help sighing.
Gather in Beijing! The countdown to openi 2020
WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
The AI method put forward by China has more and more influence. Tianda et al. Mined the development law of AI from a large number of literatures
Shh! Is this really good for asynchronous events?
Discussion on the development practice of aspnetcore, a cross platform framework
【:: 是什么语法?】
零基础打造一款属于自己的网页搜索引擎
Pollard's Rho algorithm
The difference between gbdt and XGB, and the mathematical derivation of gradient descent method and Newton method
Introduction to X Window System
Named entity recognition in natural language processing: tanford core LP ner (1)
Introduction to the structure of PDF417 bar code system
What if the front end doesn't use spa? - Hacker News
Building a new generation cloud native data lake with iceberg on kubernetes
Try to build my mall from scratch (2): use JWT to protect our information security and perfect swagger configuration
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!