In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the communication behavior of Spring affairs". In the daily operation, I believe that many people have doubts about the communication behavior of Spring affairs. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the communication behavior of Spring affairs". Next, please follow the editor to study!
First, the characteristics of the transaction ACID
I can't remember the spelling of these four English words.
Atomicity: a transaction is a series of atomic operations that either succeed or fail.
Consistency: once completed (success or failure), make sure that the series of business states in which it is located are consistent, that they are either successful or failed, and cannot be partially successful and partially failed.
Isolation: when different transactions conduct a certain business at the same time, when dealing with the same data, it is necessary to ensure that the transactions are independent of each other and do not affect each other's data.
Durability: once the transaction is completed, no matter what systematic error occurs, the data after the transaction execution is persisted and will not be changed due to restart or other operations.
II. Definition and case study of spring transaction propagation characteristics.
Let's give a definition and then do a simple code analysis separately.
Baidu image is given for your reference. First of all, if you want to use the xml of transaction spring in the project, you must open the transaction. The following features are generally configured in the xml attribute.
Configuration like this must be available, otherwise everything has nothing but Dongfeng, this is DB transactions there are JTA and JPA as well as Herbernate, etc., there is no explanation here, Baidu can be on its own.
3. Case analysis transaction propagation 7 behaviors 1. No transaction. At this time, the first insertion of id 16 succeeds, and the second insertion fails, and the first data is retained in the database.
No transaction running
2. Propagation_required, the default transaction propagation behavior required. Delete the data with an id of 16 in the table in experiment 2 so as not to affect the next test. @ Transactional (propagation=Propagation.REQUIRED) = = @ Transactional these two functions are the same. No transaction is created, a transaction execution is created.
The propagation behavior of the transaction is required
The result is that neither data is inserted because the transaction is rolled back because of the primary key conflict.
3. Propagation_supports, join the transaction if there is a transaction in the current program, and run in a non-transaction if there is no transaction
The propagation behavior of the transaction is supports
Because the caller runs in a non-transaction because it does not use a transaction, the first piece of data from the first is inserted.
4. Propagation_mandatory, which must be run in a transaction, otherwise an exception will be thrown. The word mandatory has a mandatory meaning. We use required instead of mandatory by default because mandatory cannot automatically create transactions.
The propagation behavior of the transaction is manatory
Because there is no transaction on the outer layer of the call, the two pieces of data are not inserted. Let's think about what happens in the following way of writing.
Propagation behavior of transaction mandatory
5. Propagation_ required _ new, regardless of whether the transaction exists or not, another transaction will be started. If the transaction exists, the current transaction will be suspended and the newly added transaction will be re-executed.
Propagation behavior of transaction required_new
As a result, like require, neither of the two pieces of data is stored in the database, and the only conflict causes the first piece of data to be rolled back. You can think about the following two situations.
Scenario 1 will the exception thrown by the new transaction cause the peripheral transaction to be rolled back?
Scenario 2 will the failure of the peripheral transaction result in a committed rollback of the new transaction?
6. Propagation_ not _ support, which means that the transaction is not running in the transaction. If a transaction exists, the transaction will be suspended.
Propagation behavior of transaction not_suppoted
In this scenario, if you take one step according to my idea, you can think of the entry of id 17, the second primary key conflict although notSupportSonTransationsl () this method does not have a transaction to affect the first entry, but the peripheral transaction id of 16 should be rolled back, so there is only one data id=17 in the library.
Existing transaction found for transaction marked with propagation 'never' "class=" reference-link "> 7. Propagation_never indicates that the current method cannot be run in a transaction. If there is a transaction, an exception will be thrown-- > Existing transaction found for transaction marked with propagation' never'
Propagation behavior of transaction NEVER
8. Propagation_nested, this kind of nested transaction, if there is no transaction in the periphery, it will start another transaction, which can be committed or rolled back independently with the peripheral transaction (this sentence should not be misunderstood). In the following case, none of the same data has fallen into the database.
Propagation behavior of transaction nested
At this point, the study on "what is the communication behavior of Spring transactions" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.