Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the failure scenarios of Spring transactions

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly talks about "what are the failure scenarios of Spring transactions". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what are the failure scenarios of Spring transactions.

1. The transaction of the database on which the Spring transaction ultimately depends, if mysql is used, the execution engine is innodb; because only innoDB supports transactions.

2. The transaction of Spring is based on aop, so the transaction is managed by the Spring container in bean; the objects you new are definitely not allowed.

3. The Spring transaction label @ Transactional must be annotated on the public method. Private, protected, default, and finally-decorated methods or classes, as well as static methods, transactions are invalidated.

4. Internal method calls in the same class will invalidate the transaction. The this is called, and the transaction on the updateOrder in the following figure will be invalidated. You can define another service and call the updateOrder in service to take effect.

5. Multithreaded calls to transactions will fail. Transactions are built on the same data link, and multiple threads may not get the same connection, so the transaction will fail. The doOtherThing () in the figure below throws an exception, which is impossible for add to roll back.

6. Transaction propagation. When you annotate @ Transactional, you can specify the propagation parameter. Extending its configuration does not support transactions.

Propagation.NOT_SUPPORTED, this type of propagation feature does not support transactions and throws an exception if there is a transaction.

Currently, only these three propagation features create new transactions: NESTED,REQUIRES_NEW,REQUIRED.

7. When an exception is encountered, it will be rolled back if it is RuntimeException, but not otherwise, unless @ Transactional (rollbackFor = Exception.class) is customized. This configuration is limited to Throwable exception classes and their subclasses.

8. If you swallow the abnormality and try catch, you will not roll.

9. Too many transactions are nested, resulting in too many rollbacks. I would like to roll doOtherThing () below, but if doOtherthing throws an exception and add receives it, it will also roll back. It is better to catch the exception in roleService.doOtherThing ().

At this point, I believe you have a deeper understanding of "what are the failure scenarios of Spring transactions?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report