Basic knowledge of affairs

1. The characteristics of the transaction ACID
        1) Atomicity (Atomicity) Atomicity means that the transaction is an inseparable unit of work, and the operations in the transaction either occur or do not occur. 

        2) Consistency (Consistency) In a transaction, the integrity of the data before and after the transaction must be consistent.

        3) Isolation Multiple transactions. The isolation of transactions means that when multiple users access the database concurrently, the transactions of one user cannot be interfered by the transactions of other users, and the data between multiple concurrent transactions must be isolated from each other.

       4) Durability Durability refers to the fact that once a transaction is committed, it changes the data in the database permanently, and then it should not have any impact on the database even if it fails.

    2. Concurrent access problems-caused by isolation
    If you do not consider isolation, there are 3 concurrent access problems in the transaction.

        1) Dirty read (read uncommitted): The B transaction reads the data that the A transaction has not yet submitted, and as a result, the transaction A rolls back ------ The B transaction is required to read the data submitted by the A transaction

        2) Non-repeatable read (read committed): A transaction performs updates and other operations, and the content of the data read twice in the B transaction is inconsistent, that is, the content of the data read multiple times is inconsistent ----- What is required is more than one transaction The data is consistent during the second reading --- unpdate

        3) phantom read / virtual read (repeatable read): A transaction is inserted before and after the transaction A data is deleted and B transactions are updated suddenly appears to increase or decrease the number of rows that affect the number of rows ----- requires multiple reads in a transaction The amount of data taken is the same-insert delete

    3. Isolation level of the transaction
        1) read uncommitted: read uncommitted data: no problem can be solved

        2) read committed: read the data that has been submitted: dirty reads can be resolved ---- oracle default

        3) repeatable read: reread read: can solve dirty reads and non-repeatable reads --- mysql default

        4) serializable: serialization: can solve dirty read non-repeatable read and virtual read --- equivalent to lock table
 

2. Seven transaction propagation behaviors in Spring The propagation behavior of
transactions, the default value is Propagation.REQUIRED. You can manually specify other transaction propagation behavior, as follows:

(1)Propagation.REQUIRED

If a transaction currently exists, the transaction is added, and if no transaction currently exists, a new transaction is created.

(2)Propagation.SUPPORTS

If there is currently a transaction, the transaction is added; if there is no transaction, the operation continues in a non-transactional manner.

(3)Propagation.MANDATORY

If there is currently a transaction, the transaction is added; if there is no current transaction, an exception is thrown.

(4)Propagation.REQUIRES_NEW

Re-create a new transaction, if there is currently a transaction, delay the current transaction.

(5)Propagation.NOT_SUPPORTED

Run in a non-transactional way, if there is currently a transaction, suspend the current transaction.

(6)Propagation.NEVER

Run in a non-transactional manner, if a transaction currently exists, an exception is thrown.

(7)Propagation.NESTED

If not, create a new transaction; if there is, nest other transactions in the current transaction.
 

 

Published 13 original articles · praised 3 · visits 4981

Guess you like

Origin blog.csdn.net/u010919402/article/details/97169511