当前位置:网站首页>事务的本质和死锁的原理
事务的本质和死锁的原理
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
边栏推荐
- Use modelarts quickly, zero base white can also play AI!
- What knowledge do Python automated testing learn?
- 新建一个空文件占用多少磁盘空间?
- Network programming NiO: Bio and NiO
- 百万年薪,国内工作6年的前辈想和你分享这四点
- 前端未來趨勢之原生API:Web Components
- Python filtering sensitive word records
- Python基础变量类型——List浅析
- Flink's datasource Trilogy 2: built in connector
- The difference between gbdt and XGB, and the mathematical derivation of gradient descent method and Newton method
猜你喜欢

Construction of encoder decoder model with keras LSTM

IPFs rudder filecoin landing at the same time, fil currency price broke a thousand

检测证书过期脚本

华为云微认证考试简介

Named entity recognition in natural language processing: tanford core LP ner (1)

【自学unity2d传奇游戏开发】地图编辑器

一部完整的游戏,需要制作哪些音乐?

(1) ASP.NET Introduction to core3.1 Ocelot

事件监听问题

What course of artificial intelligence? Will it replace human work?
随机推荐
FastThreadLocal 是什么鬼?吊打 ThreadLocal 的存在!!
Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
Individual annual work summary and 2019 work plan (Internet)
事件监听问题
For a while, a dynamic thread pool was created, and the source code was put into GitHub
一部完整的游戏,需要制作哪些音乐?
Lane change detection
【自学unity2d传奇游戏开发】如何让角色动起来
游戏开发中的新手引导与事件管理系统
WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
用一个例子理解JS函数的底层处理机制
Network security engineer Demo: the original * * is to get your computer administrator rights! [maintain]
Details of dapr implementing distributed stateful service
Free patent download tutorial (HowNet, Espacenet)
Outsourcing is really difficult. As an outsourcer, I can't help sighing.
The importance of big data application is reflected in all aspects
Python filtering sensitive word records
面试官: ShardingSphere 学一下吧
一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试
DRF JWT authentication module and self customization