当前位置:网站首页>@Propagation property of transactional requires_ New in-depth understanding
@Propagation property of transactional requires_ New in-depth understanding
2022-07-01 06:29:00 【ydfind】
Premise
spring boot project ;sql server;druid Connection pool ;
Conclusion
requires_new Propagation properties , A new transaction will be created ( New connection ), Hanging up old business means , In fact, it is because of the use of ThreadLocal To preserve DB Link information , Need to put ThreadLocal Only when it is processed into the information of the current transaction .
So two transactions There is also a competitive relationship of resources , Here is an example , Outer Affairs A REQUIRED, A new record will be inserted into test_a; Internal affairs B Will inquire about test_a All records , because sql server Default read committed Isolation level , So we need to wait until A After submission , To find out , But the business A Has been suspended , need B You can continue to run after execution .
That is, there is such a situation , Business A need B You can continue to run after execution , And the business B Waiting for business A Submit to continue , So it's locked !!!
If we put things B, namely BService Methods isolation = Isolation.READ_UNCOMMITTED Set the isolation level lower , There will be no deadlock !
Code examples studied
Make a use case first , stay springboot Inside the project
@RestController
@RequestMapping(value = "/test/transational/requiresnew", produces = "application/json;charset=UTF-8")
public class TransactionalRequiresNewController {
@Autowired
private AService aService;
/**
* Outer layer required, Inner layer requires_new
* Insert new record in outer layer key1;
* Execute the inner layer ,selectAll, Insert new record key2;
* Insert a new record twice in the outer layer key3, Trigger error rollback ;
*
* expect :
* 1. Will fall into a dead cycle , Because the insertion of the outer layer was not submitted ; Inner layer selectAll Been waiting ;
* @return
*/
@GetMapping("/deadLock")
public String requiresNewDeadLock() {
try {
String s = aService.requiresNewDeadLock();
System.out.println("requiresNewDeadLock: " + s);
return s;
} catch (Exception e) {
e.printStackTrace();
return "error";
}
}
}
// AService
@Autowired
private BService bService;
@Transactional(propagation = Propagation.REQUIRED)
@Override
public String requiresNewDeadLock() {
keywordDao.insertToA("requiresNewDeadLock1");
return bService.requiresNewDeadLock();
}
// BService
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public String requiresNewDeadLock() {
// Will deadlock here . Previous transaction A Insert new data , But did not submit ,sql server Read submitted by default , So here requires_new New transaction B Been waiting ;
List<String> strings = keywordDao.selectAllKeywordInA();
return "ok";
}
边栏推荐
- SystemVerilog learning-09-interprocess synchronization, communication and virtual methods
- 【Unity Shader 消融效果_案例分享】
- Discrimination between left and right limits of derivatives and left and right derivatives
- SQL中DML语句(数据操作语言)
- 【ITSM】什么是ITSM,IT部门为什么需要ITSM
- [ITSM] what is ITSM and why does it department need ITSM
- 记磁盘扇区损坏导致的Mysql故障排查
- [ManageEngine Zhuohao] the role of LAN monitoring
- C#如何打印输出原版数组
- Pol8901 LVDS to Mipi DSI supports rotating image processing chip
猜你喜欢

Promise

High order binary search tree
![[ITSM] what is ITSM and why does it department need ITSM](/img/e1/85b5f00f124829b6a6b40c5cf621bd.png)
[ITSM] what is ITSM and why does it department need ITSM

C language course set up library information management system (big homework)

Student attendance system for C language course (big homework)

【ManageEngine】如何实现网络自动化运维
![[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform](/img/a4/b1476515260e3af0ca0dcc031deb98.png)
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform

SQL语句

C语言课设物业费管理系统(大作业)

图片服务器项目测试
随机推荐
B-tree series
[ManageEngine Zhuohao] mobile terminal management solution, helping the digital transformation of Zhongzhou aviation industry
【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
数据库对象:视图学习记录
Projects and dependencies in ABP learning solutions
请求模块(requests)
C语言课设图书信息管理系统(大作业)
JMM details
异常检测方法梳理,看这篇就够了!
虚幻 简单的屏幕雨滴后处理效果
SystemVerilog learning-10-validation quantification and coverage
端口扫描工具对企业有什么帮助?
Three minutes to quickly understand the whole process of website development
C#如何打印输出原版数组
DML statement in SQL (data operation language)
Promise
【ManageEngine卓豪】局域网监控的作用
Excel visualization
[leetcode] day91- duplicate elements exist
【Unity Shader 消融效果_案例分享】