[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)