当前位置:网站首页>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实例,当外围抛出异常时候,不会影响内围业务正常存入数据库
边栏推荐
- Machine learning by Li Hongyi 2. Regression
- Flink 在 讯飞 AI 营销业务的实时数据分析实践
- 忆凤姐
- Audio and video+
- Pyechart offline deployment
- pytest接口自动化测试框架 | 通过标记表达式执行用例
- Understand the string class
- Preliminary test yolov7
- Live broadcast preview at 19:30 on July 27: harmonyos3 and Huawei's full scene new product launch
- 了解 useRef 一篇就够了
猜你喜欢

3.2 创建菜单与游戏页面(下)

Hashtable

Application scheme of ankerui residual pressure monitoring system in residential quarter

Is it easy to find a job after programmer training?

一些实用、常用、效率越来越高的 Kubernetes 别名

Exploration on cache design optimization of community like business

征婚故事

【活动早知道】LiveVideoStack近期活动一览

V00 - 年纪大了,想做啥就做啥吧

Some practical, commonly used and increasingly efficient kubernetes aliases
随机推荐
大佬们,cdc oracle 怎么设置从指定scn号开始读取,或是怎么设置只读全量的归档,不去读取快
Exploration on cache design optimization of community like business
Swagger2.9.2 tutorial and swagger3.0.0 tutorial
Question and answer No. 48: geek appointment - construction path of observable system
Meiker Studio - Huawei 14 day Hongmeng equipment development practical notes 8
Wechat applet - Advanced chapter Lin UI component library source code analysis button component (I)
The latest heart-shaped puzzle applet source code + with flow master
3.2 create menu and game pages (Part 2)
科目三 掉头与转弯
MILA旗下初创企业Ubenwa获得250万美元投资,研究婴儿健康AI诊断
系统调用捕获和分析完结篇制作系统调用日志收集系统
忆凤姐
百问百答第48期:极客有约——可观测体系的建设路径
Understanding useref is enough
pytest接口自动化测试框架 | pytest常用插件
[cloud resident co creation] decrypt how sparkrtc realizes ultra-low latency interaction globally
Data center construction (II): brief introduction to data center
Database composition indexes and constraints
Colt DCS is serious about building a green data center!
pytest接口自动化测试框架 | pytest配置文件