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 is Spring transaction management like?

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

Share

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

What is Spring transaction management like? in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Spring transaction management includes transaction propagation, transaction isolation, transaction concurrency processing and so on.

Transaction propagation

1. Required: the method executes in a transaction, and if the called method is in a transaction, the transaction is used, otherwise a new transaction will be created. (you must have it, use it if you have it, and build it without it)

2. Mandatory: if the method is called by the customer running in the transaction, the method is executed in the customer's transaction. If the customer is not associated with the transaction, the container throws a TransactionRequiredException. (must have it, use it if you have it, and report it correctly)

3. Requiresnew: the method will be executed in a new transaction, and if the called method is already in a transaction, the old transaction will be paused. Restores the old transaction after the call ends. (it must be built, whether it is or not.)

4. Supports: if the method is called in a transaction, the transaction is used, otherwise the transaction is not used. (whether or not you are in the middle, you can use it if you have it, and you don't need it.)

5. Not_supported: if a method is called in a transaction, the container terminates the transaction before the call. After the call ends, the container resumes the customer transaction. If the customer is not associated with a transaction, the container does not run in this method to start a new transaction. Use the notsupported attribute to identify methods that do not require transactions. Because transactions incur higher performance costs, this property can improve performance. (no need, just suspend the transaction, do not run directly)

6. Never: if this method is called in a transaction, the container throws a RemoteException. If the customer is not associated with a transaction, the container does not start a new transaction before running into the method. (must not have, report error if there is, run directly if there is no)

Transaction isolation

The reason for using thing isolation is because of some errors caused by the concurrency of things.

Concurrency issues:

Dirty read: a transaction reads an uncommitted transaction

Non-repeatable: different results will be returned when the same data is read multiple times in the same transaction

Illusion: one transaction reads insert data committed by another transaction.

Transaction concurrency processing:

Shared lock: a shared lock is used to read data, which allows other transactions to read a locked resource at the same time, but does not allow other transactions to update it.

Exclusive lock: an exclusive lock is used to modify data. It locks resources that cannot be read or modified by other transactions.

Update locks: update locks are used to lock resources that may be modified during the initialization phase of the update operation, thus avoiding deadlocks caused by the use of shared locks.

Transaction isolation level:

ReadUncommitted: reads uncommitted data, which instructs the database to read the data without any locks. In this case, the transaction can read the uncommitted data, resulting in dirty reading, unrepeatable reading and phantom reading.

ReadCommited:

This option returns only data that has been submitted before read time. Therefore, dirty reading can be avoided, but there will be unrepeatable reading and phantom reading.

RepeatableRead: this option ensures repeatability and avoids dirty and non-repeatable readings.

Serializable: this option avoids dirty, unrepeatable, and phantom reading, and is the strictest isolation level.

The answer to the question about Spring transaction management is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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