Java basics-transactions and java transactions
I. Transactions
Simply put, transactions are one thing. All transaction-related content is centered around this matter.
Ii. Features of transactions: ACID
A: Atomicity (Atomicity), the transaction must be an integral whole.
C: Consistency (Consistency). After database operations are performed, the data will not be damaged. For example, to transfer money from account A to account B, you must ensure that account B can increase the corresponding amount of money after account A deducts money.
I: Isolation (Isolation). If multiple people operate on the same piece of data at the same time, it will be very troublesome if they do not control it. This control refers to isolation.
D: Durability (Durability). If an insert statement is executed, the database must ensure that a piece of data is permanently stored in the database.
The ACID feature of transactions is used to ensure data consistency. Isolation is a means to ensure transaction consistency.
Iii. transaction Isolation Level)
As mentioned above, the isolation of transactions. The control refers to the isolation level here.
(1) READ_UNCOMMITED: Read uncommitted
(2) READ_COMMITED: Read committed
(3) REPEATABLE_READ: repeatable
(4) SERIALIZABLE:
From top to bottom, the concurrency is getting worse, and the security is getting higher and higher.
Iv. Problems in transactions
(1) Dirty read -- transaction A reads the uncommitted data of transaction B and performs other operations on this basis.
(2) do not read repeatedly -- transaction A reads the changed data committed by transaction B.
(3) Phantom read-transaction A reads new data committed by transaction B.
Dirty reads are not allowed under any circumstances.
V. Correspondence between the isolation level of transactions and problems in transactions
In fact, the isolation level of the transaction exists to solve the problems in the transaction.
The default isolation level of MySQL is READ_COMMITED.
It should be noted that the transaction isolation level specification mentioned here is proposed by JDBC.
At the database level, the isolation level is controlled by locks. when data is inserted, the table is locked ". When data is updated, the row is locked ".
6. summary as a chart