Spring Learning Notes Transaction (i)

Source: Internet
Author: User
Tags websphere application server

Ruchunli's work notes , a good memory is worse than a bad pen


A transaction is a unit of work that consists of a series of operations that are indivisible, that is, either all operations are done, or all operations are not done, which is the transaction.
Transactions must meet the acid (atomicity, consistency, isolation, and durability) characteristics and are indispensable:
Atomicity (atomicity): That is, the transaction is the smallest unit of work, and the operations within the transaction either do it all or do nothing;
Consistency (consistency): The data of the database is in the correct state before the transaction execution, and the data of the database is in the correct state after the transaction execution is completed;
Isolation (Isolation): There is no effect between concurrent transaction execution, and operations within one transaction have no effect on other transactions;
Persistence (Durability): Once a transaction succeeds, its data changes to the database must be permanent.

In the actual project development of the database operations are generally executed concurrently, that is, there are multiple transactions concurrent execution, concurrent execution may encounter problems, the current common problems are as follows:
Update lost: Two transactions update a row of data at the same time, the update of the last transaction overwrites the update of the first transaction, resulting in the loss of data for the first transaction update, due to the absence of a lock;
Dirty reads: One transaction sees the uncommitted update data of another transaction;
Non-repeatable reads: In the same transaction, multiple reads of the same data return different results; that is, there are other transactions that have changed the data;
Phantom read: One transaction reads the inserted data from another transaction during execution, i.e. reads a batch of data at the beginning of the first transaction, but then another transaction inserts new data and commits, at which point the first transaction reads the data but finds one more, which is like an illusion.


To address these concurrency issues, the database isolation level needs to be addressed, with four isolation levels defined in the standard SQL specification:
READ UNCOMMITTED: The lowest isolation level, a transaction can read to other transactions uncommitted update data, very insecure, there may be updates lost, dirty read, non-repeatable read, Phantom Read;
Read Committed: One transaction can read the updated data submitted by another transaction, cannot see the uncommitted update data, it is not possible to lose the update, dirty read, but may appear non-repeatable read, Phantom Read;
REPEATABLE READ (REPEATABLE Read): guarantees that multiple queries executed in the same transaction will return the same result, not affected by other transactions, may result in missing updates, dirty reads, non-repeatable reads, but phantom reads may occur;
Serialization (Serializable): The highest isolation level, where transactions are not allowed to execute concurrently, but must be serialized for the most secure, impossible updates, dirty reads, non-repeatable reads, and Phantom reads.

Database transaction types have local and distributed transactions:
Ground affairs: Ordinary business, single database operation of acid;
Distributed transactions: Transactions that span multiple homogeneous or heterogeneous databases.
Java transaction types have JDBC transactions and JTA transactions:
JDBC Transaction: Manages the transaction through the control of the connection object;
JTA transaction: JTA refers to the Java Transaction API (Java Transaction API), is the Java EE Database transaction specification, JTA only provides the transaction management interface, by the application server vendor (such as WebSphere application Server) provides implementations where JTA transactions are more powerful than JDBC and support distributed transactions.



This article is from the "world of Stuffy Gourd" blog, please be sure to keep this source http://luchunli.blog.51cto.com/2368057/1812650

Spring Learning Notes Transaction (i)

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.