In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article shares with you the content of a sample analysis of Spring transaction failures. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
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 ().
Supplementary note:
MySQL and the engine is MyISAM, the transaction will not work because MyISAM does not support transactions, but the InnoDB engine supports transactions.
The annotation @ Trasactional works only if you add a transaction to a public-decorated method. If you add non-protect, private, etc.
In the method of public modification, the transaction will expire.
If within the method where the transaction is turned on, the try-catch statement block is used to catch the exception without throwing the exception to the outer layer, the transaction will not work.
When a method is called between different classes, the exception occurs in the non-transactional method A, but it is not generated by the called method B, and the transaction of the called method B is invalid. The transaction is valid only if the exception occurs in method B that opens the transaction.
Thank you for reading! This is the end of this article on "sample Analysis of Spring transaction failure". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.