In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what are the propagation characteristics of Spring transactions", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the communication characteristics of Spring transactions" can help you solve your doubts? let's follow the editor's ideas to learn new knowledge.
Set the transaction propagation property through Propagation in Spring, which provides one of our features about transaction propagation:
1. PROPAGATION_REQUIRED: supports the current transaction. If there is no current transaction, create a new transaction. This is the most common choice.
2. PROPAGATION_SUPPORTS: supports the current transaction and executes in a non-transactional manner if there is no current transaction.
3. PROPAGATION_MANDATORY: supports the current transaction, and throws an exception if there is no current transaction.
4. PROPAGATION_REQUIRES_NEW: create a new transaction and suspend the current transaction if it exists.
5. PROPAGATION_NOT_SUPPORTED: perform the operation in a non-transactional manner, suspending the current transaction if there is a current transaction.
6. PROPAGATION_NEVER: executes in a non-transactional manner, throwing an exception if a transaction currently exists.
7. PROPAGATION_NESTED: support the current transaction, add Savepoint points, commit or rollback synchronously with the current transaction.
Explain it in detail:
1. PROPAGATION_REQUIRED: join the transaction that is currently being executed that is not in another transaction, then a new transaction will be created. For example, if the transaction level of ServiceB.methodB is defined as PROPAGATION_REQUIRED, then because ServiceA.methodA has already started a transaction when ServiceA.methodA is executed, calling ServiceB.methodB,ServiceB.methodB will not start a new transaction when you see that you are already running inside the transaction of ServiceA.methodA. And if ServiceA.methodA runs and finds that he is not in a transaction, he assigns a transaction to himself. In this way, if an exception occurs in ServiceA.methodA or anywhere within ServiceB.methodB, the transaction will be rolled back. Even if the transaction for ServiceB.methodB has been committed, ServiceA.methodA will be rolled back when fail rolls back, and ServiceB.methodB will roll back.
2. PROPAGATION_SUPPORTS: if you are currently in a transaction, that is, running as a transaction, if you are no longer in a transaction, then running as a non-transaction.
3. PROPAGATION_MANDATORY: must be run in a transaction. That is, he can only be called by one parent transaction. Otherwise, he will throw an exception.
4. PROPAGATION_REQUIRES_NEW: this is a bit of a roundabout. For example, if we design that the transaction level of ServiceA.methodA is PROPAGATION_REQUIRED,ServiceB.methodB and the transaction level of ServiceA.methodA is PROPAGATION_REQUIRES_NEW, then when the execution reaches ServiceB.methodB, the transaction of ServiceA.methodA will be suspended and ServiceB.methodB will start a new transaction and wait for the transaction of ServiceB.methodB to complete before he continues to execute. The transaction difference between him and PROPAGATION_REQUIRED is the degree of rollback of the transaction. Because ServiceB.methodB is a new transaction, there are two different transactions. If the ServiceB.methodB has been committed, then the ServiceA.methodA fails to roll back, and ServiceB.methodB will not roll back. If ServiceB.methodB fails to roll back, if the exception he throws is caught by ServiceA.methodA, the ServiceA.methodA transaction may still commit.
5. PROPAGATION_NOT_SUPPORTED: currently, transactions are not supported. For example, if the transaction level of ServiceA.methodA is PROPAGATION_REQUIRED and the transaction level of ServiceB.methodB is PROPAGATION_NOT_SUPPORTED, then when ServiceB.methodB is executed, the transaction of ServiceA.methodA is suspended and he finishes running in a non-transactional state before continuing the transaction of ServiceA.methodA.
6. PROPAGATION_NEVER: cannot run in a transaction. Assuming that the transaction level of ServiceA.methodA is PROPAGATION_REQUIRED and the transaction level of ServiceB.methodB is PROPAGATION_NEVER, then ServiceB.methodB will throw an exception.
7. PROPAGATION_NEST: the key to understanding Nested is savepoint.
The difference between him and PROPAGATION_REQUIRES_NEW is that PROPAGATION_REQUIRES_NEW has another transaction, which will be independent of his parent transaction, while Nested's transaction is dependent on his parent transaction, and his commit is to be committed with his parent transaction. In other words, if the parent transaction is finally rolled back, he will also roll back. The advantage of Nested transactions is that he has a savepoint. In other words, if ServiceB.methodB fails to roll back, ServiceA.methodA will also roll back to the savepoint point, and ServiceA.methodA can choose another branch, such as ServiceC.methodC, to continue execution to try to complete its own transaction. However, this transaction is not defined in the EJB standard.
After reading this, the article "what are the communication characteristics of Spring transactions" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.