其他分享
首页 > 其他分享> > 初识事务,事务隔离级别,事务传播行为

初识事务,事务隔离级别,事务传播行为

作者:互联网

本篇文章会介绍以下几个概念:事务,事务隔离级别,spring事务的传播模式。在介绍事务时会引出原子性的概念,在介绍事务隔离级别的时候会引出脏读和幻读的概念。

事务
什么是事务?
事务最开始是数据库中的概念,它把一系列的操作统一为一个整体,这一系列的操作要么同时成功,要么同时失败。一个事务基本的操作是:

开启事务
如果发生了错误,进行回滚
如果没有发生错误,则提交事务
为什么要有事务?
在我们处理简单业务的时候,比如说一条插入数据的操作,只会得到两个结果,要么插入成功,要么插入失败,这对应到代码逻辑上是很简单的。
我们称这样的操作具有原子性。

但是我们的业务往往不会只有插入一条数据那么简单,可能用户点击一个按钮后,我们需要插入一条数据和删除一条数据。由于每个操作都有可能成功和失败,这个时候我们就有了2^2=4种情况,这下编程起来就麻烦了。

为了方便编程(也为了符合实际业务逻辑),我们引入开头所述的事务机制,把两个操作放在一个事务里面,使这两个操作具备原子性,这样一来业务处理起来就方便多了。

事务隔离级别
上面我们谈到了操作数据库的时候会使用到事务,接下来引入的问题就是:在数据库中,难免会出现多个事务同时操作数据的情况,这时数据库设置的事务隔离级别不同,会出现不同的数据操作结果,经典的脏读与幻读也诞生于此。

首先给出并发访问时,不同事务隔离级别下的情况表:

事务隔离级别 脏读 不可重复读 幻读
read uncommitted 读未提交 会 会 会
read committed 读提交 不会 会 会
repeatable read 可重复读 不会 不会 会
serializable 串行化 不会 不会 不会
可以看到事务隔离级别越高,产生的问题越少,但是相应的性能是会降低的,下面通过几个例子分别阐述不同事务隔离级别下发生的问题:

读未提交

当事务隔离设置为读未提交时,最容易产生的问题是脏读。读未提交指的是当前事务可以读到其他事务未提交的数据:假设一位父亲给他的儿子打生活费,本来一个月2000但是不小心手抖多打了1000变成3000,这时儿子去商店消费,查询余额的时候就多了3000。由于父亲的事务还没提交,便立马回滚事务,重新打过去2000生活费。

这个时候儿子读到的余额就是脏数据,产生的原因是读取了其他事务未提交的数据。

读提交

只要将事务隔离级别设置为读提交就能解决上面的脏读问题,他能保证当前事务只能读到其他事务已经提交的数据。但是读提交会面临一个新问题:不可重复读。

比如说儿子拿着卡到商店消费,买单的时候(开启当前事务),系统检测到卡里只有500元。这个时候父亲给儿子转了2000块生活费,当儿子准备扣费的时候再查询余额发现变成了2500元(这个查询发生在父亲的转账事务提交之后)

在同一个事务中,儿子的余额在不同的时候读取的值不一样,这就是不可重复读问题。想要解决这个问题,需要把事务隔离级别设置为可重复读

可重复读

在可重复读的情况下,当前事务会禁止其他事务对正在操作的数据进行更新,这样一来,父亲转账的事务就要等到儿子账号扣费结束后才能进行,从此解决了不可重复读问题。

但是可重复读级别下还可能发生一个问题叫幻读,举例如下:儿子今天在外消费了1000元,父亲查看儿子一天的消费记录(开启事务),发现一共是1000元。这个时候儿子又消费了1000元(父亲的事务仍在进行中),接着父亲打印儿子今天的消费记录,发现莫名其妙地变成了2000元,多了一条消费记录。

像这种当前事务在操作的过程中,由于别的事务增加或删除数据,导致当前事务操作的数据突然变多或变少的情况,就叫幻读。想要解决幻读,需要把事务隔离级别升级为串行化

串行化

当事务隔离级别为串行化时,所有事务都是串行执行的,对应上面的例子:父亲在查看当天消费记录时,儿子是不能消费的。这么一来事务并发带来的问题都能解决,但是效率很低。

扩展

在常用的数据库中Orcale默认的事务隔离级别是读提交,而Mysql默认的是可重复读。在Mysql的InnoDB引擎中,虽然事务隔离级别是可重复读,但是也可以解决幻读问题,背后的原理是在数据行之间添加间隙锁,防止数据的插入与删除。

具体选择那一种事务隔离级别,要看具体的业务需要

事务传播行为
事务的传播行为从字面上也是挺好理解的:想要发生传播就一定要有两个以上的物体,而这里指的是两个方法都要在事务中进行,当一个事务方法A调用另一个事务方法B时,另一个事务方法B该如何运行。

Spring一共定义了7种事务传播行为(事务方法B该如何运行):

传播行为 含义
PROPAGATION_REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中(这是最常见的选择,也是spring的默认事务传播行为)
PROPAGATION_SUPPORTS 支持当前事务,如果当前没有事务,就以非事务方式执行
PROPAGATION_MANDATORY 使用当前的事务,如果当前没有事务,就抛出异常
PROPAGATION_REQUIRES_NEW 新建事务,如果当前存在事务,把当前事务挂起
PROPAGATION_NOT_SUPPORTED 以非事务方式执行操作,如果当前存在事务,就把当前事务挂起
PROPAGATION_NEVER 以非事务方式执行,如果当前存在事务,则抛出异常
PROPAGATION_NESTED 如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则执行与PROPAGATION_REQUIRED类似的操作
平时我们最常用的是 PROPAGATION_REQUIRED,这也是spring的默认事务传播行为,理解了它就能按理推导其他的事务传播行为。

比如说当前我们有如下代码:https://github.com/bolo3m2k/rdhslbggtt/discussions/485
https://github.com/zjd6qwwu/xiellftjwv/discussions/472
https://github.com/bolo3m2k/rdhslbggtt/discussions/486
https://github.com/zjd6qwwu/xiellftjwv/discussions/473
https://github.com/bolo3m2k/rdhslbggtt/discussions/487
https://github.com/zjd6qwwu/xiellftjwv/discussions/474
https://github.com/bolo3m2k/rdhslbggtt/discussions/488
https://github.com/zjd6qwwu/xiellftjwv/discussions/475
https://github.com/bolo3m2k/rdhslbggtt/discussions/489
https://github.com/zjd6qwwu/xiellftjwv/discussions/476
https://github.com/bolo3m2k/rdhslbggtt/discussions/490
https://github.com/zjd6qwwu/xiellftjwv/discussions/477
https://github.com/bolo3m2k/rdhslbggtt/discussions/491
https://github.com/zjd6qwwu/xiellftjwv/discussions/478
https://github.com/bolo3m2k/rdhslbggtt/discussions/492
https://github.com/zjd6qwwu/xiellftjwv/discussions/479
https://github.com/zjd6qwwu/xiellftjwv/discussions/480
https://github.com/bolo3m2k/rdhslbggtt/discussions/493
https://github.com/bolo3m2k/rdhslbggtt/discussions/494
https://github.com/zjd6qwwu/xiellftjwv/discussions/481
https://github.com/zjd6qwwu/xiellftjwv/discussions/482
https://github.com/bolo3m2k/rdhslbggtt/discussions/495
https://github.com/zjd6qwwu/xiellftjwv/discussions/483
https://github.com/bolo3m2k/rdhslbggtt/discussions/496
https://github.com/zjd6qwwu/xiellftjwv/discussions/484
https://github.com/bolo3m2k/rdhslbggtt/discussions/497
https://github.com/zjd6qwwu/xiellftjwv/discussions/485
https://github.com/zjd6qwwu/xiellftjwv/discussions/486
https://github.com/zjd6qwwu/xiellftjwv/discussions/487
https://github.com/zjd6qwwu/xiellftjwv/discussions/488
https://github.com/zjd6qwwu/xiellftjwv/discussions/489
https://github.com/bolo3m2k/rdhslbggtt/discussions/498
https://github.com/bolo3m2k/rdhslbggtt/discussions/499
https://github.com/bolo3m2k/rdhslbggtt/discussions/500
https://github.com/zjd6qwwu/xiellftjwv/discussions/490
https://github.com/zjd6qwwu/xiellftjwv/discussions/491
https://github.com/bolo3m2k/rdhslbggtt/discussions/501
https://github.com/bolo3m2k/rdhslbggtt/discussions/502
https://github.com/zjd6qwwu/xiellftjwv/discussions/492
https://github.com/bolo3m2k/rdhslbggtt/discussions/503
https://github.com/zjd6qwwu/xiellftjwv/discussions/493
https://github.com/zjd6qwwu/xiellftjwv/discussions/494
https://github.com/bolo3m2k/rdhslbggtt/discussions/504
https://github.com/zjd6qwwu/xiellftjwv/discussions/495
https://github.com/bolo3m2k/rdhslbggtt/discussions/505
https://github.com/bolo3m2k/rdhslbggtt/discussions/506
https://github.com/zjd6qwwu/xiellftjwv/discussions/496
https://github.com/bolo3m2k/rdhslbggtt/discussions/507
https://github.com/bolo3m2k/rdhslbggtt/discussions/508
https://github.com/bolo3m2k/rdhslbggtt/discussions/509
https://github.com/bolo3m2k/rdhslbggtt/discussions/510
https://github.com/bolo3m2k/rdhslbggtt/discussions/511
https://github.com/zjd6qwwu/xiellftjwv/discussions/497
https://github.com/bolo3m2k/rdhslbggtt/discussions/512
https://github.com/bolo3m2k/rdhslbggtt/discussions/513
https://github.com/zjd6qwwu/xiellftjwv/discussions/498
https://github.com/bolo3m2k/rdhslbggtt/discussions/514
https://github.com/bolo3m2k/rdhslbggtt/discussions/515
https://github.com/zjd6qwwu/xiellftjwv/discussions/499
https://github.com/bolo3m2k/rdhslbggtt/discussions/516
https://github.com/zjd6qwwu/xiellftjwv/discussions/500
https://github.com/bolo3m2k/rdhslbggtt/discussions/517
https://github.com/bolo3m2k/rdhslbggtt/discussions/518
https://github.com/bolo3m2k/rdhslbggtt/discussions/519
https://github.com/zjd6qwwu/xiellftjwv/discussions/501
https://github.com/bolo3m2k/rdhslbggtt/discussions/520
https://github.com/bolo3m2k/rdhslbggtt/discussions/521
https://github.com/zjd6qwwu/xiellftjwv/discussions/502
https://github.com/zjd6qwwu/xiellftjwv/discussions/503
https://github.com/bolo3m2k/rdhslbggtt/discussions/522
https://github.com/zjd6qwwu/xiellftjwv/discussions/504
https://github.com/bolo3m2k/rdhslbggtt/discussions/523
https://github.com/zjd6qwwu/xiellftjwv/discussions/505
https://github.com/zjd6qwwu/xiellftjwv/discussions/506
https://github.com/7jxumfpc/mgmiqswogs/discussions/234
https://github.com/qyf0xklw/txdfvjrbzp/discussions/231
https://github.com/7jxumfpc/mgmiqswogs/discussions/235
https://github.com/qyf0xklw/txdfvjrbzp/discussions/232
https://github.com/7jxumfpc/mgmiqswogs/discussions/236
https://github.com/qyf0xklw/txdfvjrbzp/discussions/233
https://github.com/7jxumfpc/mgmiqswogs/discussions/237
https://github.com/qyf0xklw/txdfvjrbzp/discussions/234
https://github.com/7jxumfpc/mgmiqswogs/discussions/238
https://github.com/qyf0xklw/txdfvjrbzp/discussions/235
https://github.com/qyf0xklw/txdfvjrbzp/discussions/236
https://github.com/7jxumfpc/mgmiqswogs/discussions/239
https://github.com/qyf0xklw/txdfvjrbzp/discussions/237
https://github.com/7jxumfpc/mgmiqswogs/discussions/240
https://github.com/qyf0xklw/txdfvjrbzp/discussions/238
https://github.com/7jxumfpc/mgmiqswogs/discussions/241
https://github.com/7jxumfpc/mgmiqswogs/discussions/242
https://github.com/qyf0xklw/txdfvjrbzp/discussions/239
https://github.com/7jxumfpc/mgmiqswogs/discussions/243
https://github.com/qyf0xklw/txdfvjrbzp/discussions/240
https://github.com/7jxumfpc/mgmiqswogs/discussions/244
https://github.com/qyf0xklw/txdfvjrbzp/discussions/241
https://github.com/7jxumfpc/mgmiqswogs/discussions/245
https://github.com/7jxumfpc/mgmiqswogs/discussions/246
https://github.com/qyf0xklw/txdfvjrbzp/discussions/242
https://github.com/qyf0xklw/txdfvjrbzp/discussions/243
https://github.com/7jxumfpc/mgmiqswogs/discussions/247
https://github.com/qyf0xklw/txdfvjrbzp/discussions/244
https://github.com/7jxumfpc/mgmiqswogs/discussions/248
https://github.com/qyf0xklw/txdfvjrbzp/discussions/245
https://github.com/7jxumfpc/mgmiqswogs/discussions/249
https://github.com/qyf0xklw/txdfvjrbzp/discussions/246
https://github.com/7jxumfpc/mgmiqswogs/discussions/250
https://github.com/qyf0xklw/txdfvjrbzp/discussions/247
https://github.com/7jxumfpc/mgmiqswogs/discussions/251
https://github.com/qyf0xklw/txdfvjrbzp/discussions/248
https://github.com/7jxumfpc/mgmiqswogs/discussions/252
https://github.com/qyf0xklw/txdfvjrbzp/discussions/249
https://github.com/7jxumfpc/mgmiqswogs/discussions/253
https://github.com/qyf0xklw/txdfvjrbzp/discussions/250
https://github.com/7jxumfpc/mgmiqswogs/discussions/254
https://github.com/qyf0xklw/txdfvjrbzp/discussions/251
https://github.com/7jxumfpc/mgmiqswogs/discussions/255
https://github.com/qyf0xklw/txdfvjrbzp/discussions/252
https://github.com/7jxumfpc/mgmiqswogs/discussions/256
https://github.com/7jxumfpc/mgmiqswogs/discussions/257
https://github.com/qyf0xklw/txdfvjrbzp/discussions/253
https://github.com/7jxumfpc/mgmiqswogs/discussions/258
https://github.com/7jxumfpc/mgmiqswogs/discussions/259
https://github.com/qyf0xklw/txdfvjrbzp/discussions/254
https://github.com/7jxumfpc/mgmiqswogs/discussions/260
https://github.com/7jxumfpc/mgmiqswogs/discussions/261
https://github.com/qyf0xklw/txdfvjrbzp/discussions/255
https://github.com/qyf0xklw/txdfvjrbzp/discussions/256
https://github.com/7jxumfpc/mgmiqswogs/discussions/262
https://github.com/7jxumfpc/mgmiqswogs/discussions/263
https://github.com/qyf0xklw/txdfvjrbzp/discussions/257
https://github.com/7jxumfpc/mgmiqswogs/discussions/264
https://github.com/7jxumfpc/mgmiqswogs/discussions/265
https://github.com/qyf0xklw/txdfvjrbzp/discussions/258
https://github.com/qyf0xklw/txdfvjrbzp/discussions/259
https://github.com/qyf0xklw/txdfvjrbzp/discussions/260
https://github.com/7jxumfpc/mgmiqswogs/discussions/266
https://github.com/qyf0xklw/txdfvjrbzp/discussions/261
https://github.com/qyf0xklw/txdfvjrbzp/discussions/262
https://github.com/qyf0xklw/txdfvjrbzp/discussions/263
https://github.com/7jxumfpc/mgmiqswogs/discussions/267
https://github.com/qyf0xklw/txdfvjrbzp/discussions/264
https://github.com/7jxumfpc/mgmiqswogs/discussions/268
https://github.com/7jxumfpc/mgmiqswogs/discussions/269
https://github.com/7jxumfpc/mgmiqswogs/discussions/270
https://github.com/7jxumfpc/mgmiqswogs/discussions/271
https://github.com/7jxumfpc/mgmiqswogs/discussions/272
https://github.com/qyf0xklw/txdfvjrbzp/discussions/265
https://github.com/7jxumfpc/mgmiqswogs/discussions/273
https://github.com/7jxumfpc/mgmiqswogs/discussions/274
https://github.com/qyf0xklw/txdfvjrbzp/discussions/266
https://github.com/qyf0xklw/txdfvjrbzp/discussions/267
https://github.com/qyf0xklw/txdfvjrbzp/discussions/268
https://github.com/7jxumfpc/mgmiqswogs/discussions/275
https://github.com/qyf0xklw/txdfvjrbzp/discussions/269
https://github.com/7jxumfpc/mgmiqswogs/discussions/276
https://github.com/qyf0xklw/txdfvjrbzp/discussions/270
https://github.com/7jxumfpc/mgmiqswogs/discussions/277
https://github.com/qyf0xklw/txdfvjrbzp/discussions/271
https://github.com/7jxumfpc/mgmiqswogs/discussions/278
https://github.com/qyf0xklw/txdfvjrbzp/discussions/272
https://github.com/7jxumfpc/mgmiqswogs/discussions/279
https://github.com/qyf0xklw/txdfvjrbzp/discussions/273
https://github.com/7jxumfpc/mgmiqswogs/discussions/280
https://github.com/qyf0xklw/txdfvjrbzp/discussions/274
https://github.com/7jxumfpc/mgmiqswogs/discussions/281
https://github.com/7jxumfpc/mgmiqswogs/discussions/282
https://github.com/qyf0xklw/txdfvjrbzp/discussions/275
https://github.com/7jxumfpc/mgmiqswogs/discussions/283
https://github.com/qyf0xklw/txdfvjrbzp/discussions/276
https://github.com/qyf0xklw/txdfvjrbzp/discussions/277
https://github.com/7jxumfpc/mgmiqswogs/discussions/284
https://github.com/qyf0xklw/txdfvjrbzp/discussions/278
https://github.com/qyf0xklw/txdfvjrbzp/discussions/279
https://github.com/qyf0xklw/txdfvjrbzp/discussions/280
https://github.com/qyf0xklw/txdfvjrbzp/discussions/281
https://github.com/qyf0xklw/txdfvjrbzp/discussions/282
https://github.com/qyf0xklw/txdfvjrbzp/discussions/283
https://github.com/qyf0xklw/txdfvjrbzp/discussions/284
https://github.com/7jxumfpc/mgmiqswogs/discussions/285
https://github.com/qyf0xklw/txdfvjrbzp/discussions/285
https://github.com/7jxumfpc/mgmiqswogs/discussions/286
https://github.com/qyf0xklw/txdfvjrbzp/discussions/286
https://github.com/7jxumfpc/mgmiqswogs/discussions/287
https://github.com/7jxumfpc/mgmiqswogs/discussions/288
https://github.com/qyf0xklw/txdfvjrbzp/discussions/287
https://github.com/7jxumfpc/mgmiqswogs/discussions/289
https://github.com/7jxumfpc/mgmiqswogs/discussions/290
https://github.com/qyf0xklw/txdfvjrbzp/discussions/288
https://github.com/qyf0xklw/txdfvjrbzp/discussions/289
https://github.com/qyf0xklw/txdfvjrbzp/discussions/290
https://github.com/7jxumfpc/mgmiqswogs/discussions/291
https://github.com/qyf0xklw/txdfvjrbzp/discussions/291
https://github.com/qyf0xklw/txdfvjrbzp/discussions/292
https://github.com/7jxumfpc/mgmiqswogs/discussions/292
https://github.com/7jxumfpc/mgmiqswogs/discussions/293
https://github.com/7jxumfpc/mgmiqswogs/discussions/294
https://github.com/qyf0xklw/txdfvjrbzp/discussions/293
https://github.com/7jxumfpc/mgmiqswogs/discussions/295
https://github.com/qyf0xklw/txdfvjrbzp/discussions/294
https://github.com/7jxumfpc/mgmiqswogs/discussions/296
https://github.com/qyf0xklw/txdfvjrbzp/discussions/295
https://github.com/7jxumfpc/mgmiqswogs/discussions/297
https://github.com/7jxumfpc/mgmiqswogs/discussions/298
https://github.com/qyf0xklw/txdfvjrbzp/discussions/296
https://github.com/7jxumfpc/mgmiqswogs/discussions/299
https://github.com/7jxumfpc/mgmiqswogs/discussions/300
https://github.com/7jxumfpc/mgmiqswogs/discussions/301
https://github.com/qyf0xklw/txdfvjrbzp/discussions/297
https://github.com/7jxumfpc/mgmiqswogs/discussions/302
https://github.com/qyf0xklw/txdfvjrbzp/discussions/298
https://github.com/7jxumfpc/mgmiqswogs/discussions/303
https://github.com/7jxumfpc/mgmiqswogs/discussions/304
https://github.com/qyf0xklw/txdfvjrbzp/discussions/299
https://github.com/7jxumfpc/mgmiqswogs/discussions/305
https://github.com/qyf0xklw/txdfvjrbzp/discussions/300
https://github.com/7jxumfpc/mgmiqswogs/discussions/306
https://github.com/qyf0xklw/txdfvjrbzp/discussions/301
https://github.com/7jxumfpc/mgmiqswogs/discussions/307
https://github.com/qyf0xklw/txdfvjrbzp/discussions/302
https://github.com/7jxumfpc/mgmiqswogs/discussions/308
https://github.com/7jxumfpc/mgmiqswogs/discussions/309
https://github.com/qyf0xklw/txdfvjrbzp/discussions/303
https://github.com/qyf0xklw/txdfvjrbzp/discussions/304
https://github.com/qyf0xklw/txdfvjrbzp/discussions/305
https://github.com/7jxumfpc/mgmiqswogs/discussions/310
https://github.com/qyf0xklw/txdfvjrbzp/discussions/306
https://github.com/7jxumfpc/mgmiqswogs/discussions/311
https://github.com/7jxumfpc/mgmiqswogs/discussions/312
https://github.com/7jxumfpc/mgmiqswogs/discussions/313
https://github.com/7jxumfpc/mgmiqswogs/discussions/314
https://github.com/7jxumfpc/mgmiqswogs/discussions/315
https://github.com/7jxumfpc/mgmiqswogs/discussions/316
https://github.com/qyf0xklw/txdfvjrbzp/discussions/307
https://github.com/7jxumfpc/mgmiqswogs/discussions/317
https://github.com/qyf0xklw/txdfvjrbzp/discussions/308
https://github.com/7jxumfpc/mgmiqswogs/discussions/318
https://github.com/qyf0xklw/txdfvjrbzp/discussions/309
https://github.com/7jxumfpc/mgmiqswogs/discussions/319
https://github.com/qyf0xklw/txdfvjrbzp/discussions/310
https://github.com/qyf0xklw/txdfvjrbzp/discussions/311
https://github.com/7jxumfpc/mgmiqswogs/discussions/320
https://github.com/qyf0xklw/txdfvjrbzp/discussions/312
https://github.com/7jxumfpc/mgmiqswogs/discussions/321
https://github.com/qyf0xklw/txdfvjrbzp/discussions/313
https://github.com/7jxumfpc/mgmiqswogs/discussions/322
https://github.com/7jxumfpc/mgmiqswogs/discussions/323
https://github.com/qyf0xklw/txdfvjrbzp/discussions/314
https://github.com/7jxumfpc/mgmiqswogs/discussions/324
https://github.com/qyf0xklw/txdfvjrbzp/discussions/315
https://github.com/7jxumfpc/mgmiqswogs/discussions/325
https://github.com/qyf0xklw/txdfvjrbzp/discussions/316
https://github.com/qyf0xklw/txdfvjrbzp/discussions/317
https://github.com/7jxumfpc/mgmiqswogs/discussions/326
https://github.com/qyf0xklw/txdfvjrbzp/discussions/318
https://github.com/7jxumfpc/mgmiqswogs/discussions/327
https://github.com/qyf0xklw/txdfvjrbzp/discussions/319
https://github.com/7jxumfpc/mgmiqswogs/discussions/328
https://github.com/qyf0xklw/txdfvjrbzp/discussions/320
https://github.com/7jxumfpc/mgmiqswogs/discussions/329
https://github.com/qyf0xklw/txdfvjrbzp/discussions/321
https://github.com/7jxumfpc/mgmiqswogs/discussions/330
https://github.com/7jxumfpc/mgmiqswogs/discussions/331
https://github.com/qyf0xklw/txdfvjrbzp/discussions/322
https://github.com/qyf0xklw/txdfvjrbzp/discussions/323
https://github.com/7jxumfpc/mgmiqswogs/discussions/332
https://github.com/qyf0xklw/txdfvjrbzp/discussions/324
https://github.com/7jxumfpc/mgmiqswogs/discussions/333
https://github.com/qyf0xklw/txdfvjrbzp/discussions/325
https://github.com/7jxumfpc/mgmiqswogs/discussions/334
https://github.com/qyf0xklw/txdfvjrbzp/discussions/326
https://github.com/7jxumfpc/mgmiqswogs/discussions/335
https://github.com/qyf0xklw/txdfvjrbzp/discussions/327
https://github.com/7jxumfpc/mgmiqswogs/discussions/336
https://github.com/qyf0xklw/txdfvjrbzp/discussions/328
https://github.com/7jxumfpc/mgmiqswogs/discussions/337
https://github.com/qyf0xklw/txdfvjrbzp/discussions/329
https://github.com/7jxumfpc/mgmiqswogs/discussions/338
https://github.com/qyf0xklw/txdfvjrbzp/discussions/330
https://github.com/qyf0xklw/txdfvjrbzp/discussions/331
https://github.com/7jxumfpc/mgmiqswogs/discussions/339
https://github.com/qyf0xklw/txdfvjrbzp/discussions/332
https://github.com/7jxumfpc/mgmiqswogs/discussions/340
https://github.com/qyf0xklw/txdfvjrbzp/discussions/333
https://github.com/7jxumfpc/mgmiqswogs/discussions/341
https://github.com/7jxumfpc/mgmiqswogs/discussions/342
https://github.com/qyf0xklw/txdfvjrbzp/discussions/334
https://github.com/7jxumfpc/mgmiqswogs/discussions/343
https://github.com/qyf0xklw/txdfvjrbzp/discussions/335
https://github.com/7jxumfpc/mgmiqswogs/discussions/344
https://github.com/qyf0xklw/txdfvjrbzp/discussions/336
https://github.com/qyf0xklw/txdfvjrbzp/discussions/337
https://github.com/7jxumfpc/mgmiqswogs/discussions/345
https://github.com/7jxumfpc/mgmiqswogs/discussions/346
https://github.com/7jxumfpc/mgmiqswogs/discussions/347
https://github.com/qyf0xklw/txdfvjrbzp/discussions/338
https://github.com/7jxumfpc/mgmiqswogs/discussions/348
https://github.com/qyf0xklw/txdfvjrbzp/discussions/339
https://github.com/7jxumfpc/mgmiqswogs/discussions/349
https://github.com/qyf0xklw/txdfvjrbzp/discussions/340
https://github.com/7jxumfpc/mgmiqswogs/discussions/350
https://github.com/7jxumfpc/mgmiqswogs/discussions/351
https://github.com/qyf0xklw/txdfvjrbzp/discussions/341
https://github.com/7jxumfpc/mgmiqswogs/discussions/352
https://github.com/qyf0xklw/txdfvjrbzp/discussions/342
https://github.com/7jxumfpc/mgmiqswogs/discussions/353
https://github.com/7jxumfpc/mgmiqswogs/discussions/354
https://github.com/qyf0xklw/txdfvjrbzp/discussions/343
https://github.com/7jxumfpc/mgmiqswogs/discussions/355
https://github.com/qyf0xklw/txdfvjrbzp/discussions/344
https://github.com/7jxumfpc/mgmiqswogs/discussions/356
https://github.com/qyf0xklw/txdfvjrbzp/discussions/345
https://github.com/qyf0xklw/txdfvjrbzp/discussions/346
https://github.com/7jxumfpc/mgmiqswogs/discussions/357
https://github.com/7jxumfpc/mgmiqswogs/discussions/358
https://github.com/7jxumfpc/mgmiqswogs/discussions/359
https://github.com/7jxumfpc/mgmiqswogs/discussions/360
https://github.com/7jxumfpc/mgmiqswogs/discussions/361
https://github.com/7jxumfpc/mgmiqswogs/discussions/362
https://github.com/qyf0xklw/txdfvjrbzp/discussions/347
https://github.com/7jxumfpc/mgmiqswogs/discussions/363
https://github.com/7jxumfpc/mgmiqswogs/discussions/364
https://github.com/qyf0xklw/txdfvjrbzp/discussions/348
https://github.com/qyf0xklw/txdfvjrbzp/discussions/349
https://github.com/qyf0xklw/txdfvjrbzp/discussions/350
https://github.com/qyf0xklw/txdfvjrbzp/discussions/351
https://github.com/7jxumfpc/mgmiqswogs/discussions/365
https://github.com/qyf0xklw/txdfvjrbzp/discussions/352
https://github.com/qyf0xklw/txdfvjrbzp/discussions/353
https://github.com/7jxumfpc/mgmiqswogs/discussions/366
https://github.com/7jxumfpc/mgmiqswogs/discussions/367
https://github.com/qyf0xklw/txdfvjrbzp/discussions/354
https://github.com/qyf0xklw/txdfvjrbzp/discussions/355
https://github.com/qyf0xklw/txdfvjrbzp/discussions/356
https://github.com/qyf0xklw/txdfvjrbzp/discussions/357
https://github.com/qyf0xklw/txdfvjrbzp/discussions/358
https://github.com/7jxumfpc/mgmiqswogs/discussions/368
https://github.com/qyf0xklw/txdfvjrbzp/discussions/359
https://github.com/7jxumfpc/mgmiqswogs/discussions/369
https://github.com/qyf0xklw/txdfvjrbzp/discussions/360
https://github.com/qyf0xklw/txdfvjrbzp/discussions/361
https://github.com/7jxumfpc/mgmiqswogs/discussions/370
https://github.com/7jxumfpc/mgmiqswogs/discussions/371
https://github.com/7jxumfpc/mgmiqswogs/discussions/372
https://github.com/7jxumfpc/mgmiqswogs/discussions/373
https://github.com/qyf0xklw/txdfvjrbzp/discussions/362
https://github.com/7jxumfpc/mgmiqswogs/discussions/374
https://github.com/7jxumfpc/mgmiqswogs/discussions/375
https://github.com/qyf0xklw/txdfvjrbzp/discussions/363
https://github.com/7jxumfpc/mgmiqswogs/discussions/376
https://github.com/7jxumfpc/mgmiqswogs/discussions/377
https://github.com/qyf0xklw/txdfvjrbzp/discussions/364
https://github.com/7jxumfpc/mgmiqswogs/discussions/378
https://github.com/7jxumfpc/mgmiqswogs/discussions/379
https://github.com/qyf0xklw/txdfvjrbzp/discussions/365
https://github.com/qyf0xklw/txdfvjrbzp/discussions/366
https://github.com/qyf0xklw/txdfvjrbzp/discussions/367
https://github.com/7jxumfpc/mgmiqswogs/discussions/380
https://github.com/qyf0xklw/txdfvjrbzp/discussions/368
https://github.com/qyf0xklw/txdfvjrbzp/discussions/369
https://github.com/djvb5gwz/kdnyzskenz/discussions/853
https://github.com/tygq5nux/jkgibzxucg/discussions/839
https://github.com/djvb5gwz/kdnyzskenz/discussions/854
https://github.com/djvb5gwz/kdnyzskenz/discussions/855
https://github.com/tygq5nux/jkgibzxucg/discussions/840
https://github.com/tygq5nux/jkgibzxucg/discussions/841
https://github.com/tygq5nux/jkgibzxucg/discussions/842
https://github.com/tygq5nux/jkgibzxucg/discussions/843
https://github.com/tygq5nux/jkgibzxucg/discussions/844
https://github.com/djvb5gwz/kdnyzskenz/discussions/856
https://github.com/tygq5nux/jkgibzxucg/discussions/845
https://github.com/tygq5nux/jkgibzxucg/discussions/846
https://github.com/djvb5gwz/kdnyzskenz/discussions/857
https://github.com/tygq5nux/jkgibzxucg/discussions/847
https://github.com/djvb5gwz/kdnyzskenz/discussions/858
https://github.com/tygq5nux/jkgibzxucg/discussions/848
https://github.com/djvb5gwz/kdnyzskenz/discussions/859
https://github.com/tygq5nux/jkgibzxucg/discussions/849
https://github.com/djvb5gwz/kdnyzskenz/discussions/860
https://github.com/tygq5nux/jkgibzxucg/discussions/850
https://github.com/djvb5gwz/kdnyzskenz/discussions/861
https://github.com/tygq5nux/jkgibzxucg/discussions/851
https://github.com/tygq5nux/jkgibzxucg/discussions/852
https://github.com/djvb5gwz/kdnyzskenz/discussions/862
https://github.com/djvb5gwz/kdnyzskenz/discussions/863
https://github.com/tygq5nux/jkgibzxucg/discussions/853
https://github.com/tygq5nux/jkgibzxucg/discussions/854
https://github.com/tygq5nux/jkgibzxucg/discussions/855
https://github.com/djvb5gwz/kdnyzskenz/discussions/864
https://github.com/tygq5nux/jkgibzxucg/discussions/856
https://github.com/djvb5gwz/kdnyzskenz/discussions/865
https://github.com/tygq5nux/jkgibzxucg/discussions/857
https://github.com/djvb5gwz/kdnyzskenz/discussions/866

@Transactional(propagation = Propagation.REQUIRED)
public void methodA() {
methodB();
// do something
}

@Transactional(propagation = Propagation.REQUIRED)
public void methodB() {
// do something
}
假设我们执行methodA,由于当前还没有事务,于是就新创建一个事务。
当在methodA中调用methodB的时候,由于methodA已经存在于事务中,于是methodB便无需新创建一个事务,直接加入到methodA的事务中即可。
总结
事务能够让一系列不同的操作具有原子性。(当然事务具备ACID四大特性,本文在初步介绍时强调的是原子性)
事务隔离级别定义了事务并发操作时的访问规则。
事务传播行为定义了事务方法在执行时该怎么运用事务。

标签:mgmiqswogs,事务,github,隔离,7jxumfpc,初识,txdfvjrbzp,discussions,com
来源: https://blog.csdn.net/a_b_c104/article/details/111847981