Java basics-transactions and java transactions

Source: Internet
Author: User

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

 

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.