当前位置:网站首页>事务的本质和死锁的原理
事务的本质和死锁的原理
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 are manufacturing and new automation technologies?
- Introduction to X Window System
- 用一个例子理解JS函数的底层处理机制
- 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
- 零基础打造一款属于自己的网页搜索引擎
- It is really necessary to build a distributed ID generation service
- Read the advantages of Wi Fi 6 over Wi Fi 5 in 3 minutes
- Named entity recognition in natural language processing: tanford core LP ner (1)
- How to hide part of barcode text in barcode generation software
猜你喜欢

What are the criteria for selecting a cluster server?

Building a new generation cloud native data lake with iceberg on kubernetes

How to hide part of barcode text in barcode generation software

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

【学习】接口测试用例编写和测试关注点

What are the common problems of DTU connection

华为Mate 40 系列搭载HMS有什么亮点?

消息队列(MessageQueue)-分析

With the advent of tensorflow 2.0, can pytoch still shake the status of big brother?

游戏开发中的新手引导与事件管理系统
随机推荐
给字节的学姐讲如何准备“系统设计面试”
Cglib 如何实现多重代理?
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王涛
Flink的DataSource三部曲之一:直接API
A brief history of neural networks
代码生成器插件与Creator预制体文件解析
百万年薪,国内工作6年的前辈想和你分享这四点
Isn't data product just a report? absolutely wrong! There are university questions in this category
Asp.Net Core learning notes: Introduction
What is the purchasing supplier system? Solution of purchasing supplier management platform
Discussion on the technical scheme of text de duplication (1)
只有1个字节的文件实际占用多少磁盘空间
Recommendation system based on deep learning
Elasticsearch数据库 | Elasticsearch-7.5.0应用搭建实战
[Xinge education] poor learning host computer series -- building step 7 Simulation Environment
It's easy to operate. ThreadLocal can also be used as a cache
Xmppmini project details: step by step from the principle of practical XMPP technology development 4. String decoding secrets and message package
Building and visualizing decision tree with Python
Details of dapr implementing distributed stateful service
How to turn data into assets? Attracting data scientists