当前位置:网站首页>Transactional事务传播行为?
Transactional事务传播行为?
2022-07-26 11:46:00 【用户9919783】
事务传播行为有7种,不是与数据库交互,数据库定义的,而是spring框架自带的。
本文主要介绍三种:required、nested、required_new。
Propagation_required(传播要求):默认的,最常见的,如果当前没有事务,就新建事务执行,若有事务,就加入当前事务执行。外围方法未开启事务的情况下,内部两个事务开启此事务是互不干扰的,且不受外围异常影响。
默认传播要求下,内围事务里面若异常捕获到,则此内围事务里的其他程序正常运行。外围事务捕获到异常,外围及其其他内围事务不可以正常运行。
Propagation_supports(传播支持):支持当前事务,若没有事务,就以非事务执行。Propagation_mandatory(强制性):若当前无事务,抛出异常。
Propagation_requires_new:新建事务,若当前存在事务,吧当前事务挂起。外围方法未开启事务的情况下,内部两个事务开启此事务是互不干扰的,且不受外围异常影响。
若外围开启事务,requeired内围事务和外围事务是同时回滚的。
若requreis_new内围事务异常未被捕获,则requeired内围事务与外围事务一起回滚,其他requreis_new内围事务不受影响。
若requreis_new内围事务异常被trycatch捕获,则外围其他事务不受影响。
Propagation_not_supported(非支持):以非事务操作,若当前存在事务,吧事务挂起。
Propagation_never:以非事务方式执行,若当前存在事务,则抛出异常。
Propagation_nested(传播嵌套):如果当前存在事务,则在嵌套内执行,如果没有事务,则执行Propagation_required操作。外围方法未开启事务的情况下,内部两个事务开启此事务是互不干扰的,且不受外围异常影响。
1、propagaration_requeire_new与Propagation_nested嵌套传播区别:
Nested若外围事务开启,因为是父子嵌套事务,则子事务都随外围主事务的回滚而回滚,子事务滚回则所有事务一起回滚,除非当前子事务被trycatch捕获。而requeires_new外围事务和内围事务是两个事务,外围事务回滚不会影响内部事务。
2、Nested和requeired区别:
都会随着外围事务的回滚而一起回滚。Requeired是属于加入外围事务,因为都属于同一个事务,一旦内围事务回滚不管是否trycatch捕获,所有都一起回滚。而nested属于子事务,有单独的保存节点,所以nested方法抛出异常trycatch捕获被回滚,不会影响外围事务。
代码实例如下:
required实例,使用默认事务实例,不管是否捕获异常,全部一起回滚
nested实例,因为嵌套事务,外围内围都会随着互相回滚而回滚,除非子事务被捕获异常
required_new实例,当外围抛出异常时候,不会影响内围业务正常存入数据库
边栏推荐
- 虚拟偶像代言产品出问题谁负责? 且听律师分析
- Talking about web vitals
- 程序员培训学习后好找工作吗?
- Li Kai: the interesting and cutting-edge audio and video industry has always attracted me
- Miccai2022 paper | evolutionary multi-objective architecture search framework: application in covid-19 3D CT classification
- Pyechart offline deployment
- 滴滴被罚80亿!拿用户数据赚钱的时代结束了
- 10 reduce common "tricks"
- 科目三 掉头与转弯
- 【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
猜你喜欢

元宇宙日报|元宇宙社交 App“派对岛”产品下架;广州南沙元宇宙产业集聚区揭牌;数字经济发展部际联席会议制度推出

Pytoch -- error based on mmseg/mmdet training: runtimeerror: expected to have finished reduction in the priority iteration

The latest heart-shaped puzzle applet source code + with flow master

Li Kai: the interesting and cutting-edge audio and video industry has always attracted me

最新心形拼图小程序源码+带流量主

Pytorch——基于mmseg/mmdet训练报错:RuntimeError: Expected to have finished reduction in the prior iteration

哈希表

大咖观点+500强案例,软件团队应该这样提升研发效能!

pytest接口自动化测试框架 | pytest常用插件
![[early knowledge of activities] list of recent activities of livevideostack](/img/a5/06c13865b7adbd99d43c1a52f3fc4d.png)
[early knowledge of activities] list of recent activities of livevideostack
随机推荐
X 2 earn must rely on Ponzi startup? Where is the way out for gamefi? (top)
Cohere博客:在生产环境中运行大型语言模型-推理框架概览
基于 Flink CDC 实现海量数据的实时同步和转换
系统调用捕获和分析—Ring0层kprobe劫持系统调用
Yuancosmos daily | yuancosmos social app "Party Island" product off the shelves; Guangzhou Nansha yuanuniverse industrial agglomeration zone was unveiled; The inter ministerial joint conference system
最新心形拼图小程序源码+带流量主
Marriage seeking story
GA-RPN:引导锚点的建议区域网络
3.1 创建菜单与游戏页面——上
[communication principle] Chapter 3 -- random process [i]
Sword finger offer 25. merge two sorted linked lists
There are various signs that apple is expected to support AV1
绝对路径打开文件相比数据库查询哪个更快?
CVPR 2022 单目深度估计新SOTA—NeW CRFs:Neural Window Fullyconnected CRFs
PostgreSQL in Linux and windows installation and introductory basic tutorial
JS use webuploader to do blocking and breakpoint continuation of large files
C language code quantity statistical tool
忆凤姐
音视频+
How to use data pipeline to realize test modernization