[Spring Enterprise development practice] Several Issues about transaction concurrency, spring practice

Source: Internet
Author: User

[Spring Enterprise development practice] Several Issues about transaction concurrency, spring practice

I. Several Issues about transaction concurrency:

1) Dirty read: When two transactions operate on the same data at the same time and transaction A modifies the data before committing, transaction B accesses the transaction and uses the data, at this time, transaction A rolls back, and transaction B reads dirty data.

For example, transaction 1, modified a data transaction 2, and accessed the data after transaction 1 was modified.

At this time, transaction 1 rolls back operation transaction 2 and reads the data before rollback.

2) Non-repeated read: This occurs when the same data is read multiple times in a transaction. Transaction A queries A piece of data. when the transaction is not completed, transaction B also accesses the same data and modifies it. Therefore, because of the modification of the second transaction between the two reads of data in transaction A, the data read by the first transaction may be different.

Transaction 1, query a data transaction 2, modify a data, submit

Transaction 1: query the data again.

In this way, the data queried twice in a transaction is different, which is called non-repeated read.

3) Phantom read: When transaction A operates A pile of data, transaction B inserts A piece of data, and transaction A queries again, and finds that another piece of data is like an illusion. Similar to non-repeated reads, the difference is that one is modification, and the other is addition or deletion.

Notice: there will be no dirty reads in oracle. To prevent reading and changing data (which cannot be read repeatedly), you only need to add a "Row-Level Lock" to the operation data ", to prevent reading new data (phantom read), you must add a "table-Level Lock" to lock the entire table !!!

4) the first type of loss update: Transaction A and transaction B operate on the same data at the same time. Transaction A changes the data first, and transaction B fails to change the data again and then rolls back, roll back the data updated by B. (Cancellation loss caused by transaction cancellation)

 

5) The second type of loss update: Transaction A and transaction B operate on the same data at the same time. Transaction A changes the data first, and transaction B changes and submits the data again, overwriting the data submitted by transaction B. (Overwrite loss caused by transaction commit)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.