Home > Java > javaTutorial > body text

Why does JAVA use transactions?

anonymity
Release: 2020-09-09 09:43:16
Original
4113 people have browsed it

Why does JAVA use transactions?

What is a transaction?

Transaction generally refers to something to be done or done. In computer terms, it refers to a program execution unit (unit) that accesses and possibly updates various data items in a database. A transaction is usually caused by the execution of a user program written in a high-level database manipulation language or programming language (such as SQL, C, or Java) and is defined by statements (or function calls) in the form of begin transaction and end transaction. A transaction consists of all operations performed between the beginning of the transaction and the end of the transaction.

Why do we need transactions?

Transactions are proposed to solve data security operations. Transaction control is actually to control the safe access of data.

Let’s use a simple example: For bank transfer business, account A wants to transfer 1,000 yuan from its own account to account B. The balance of account A must first be subtracted by 1,000 yuan, and then the balance of account B must be increased by 1,000 yuan. If there is a problem with the intermediate network, and the deduction of 1,000 yuan from A's account has ended, and the operation of B fails due to network interruption, then the entire business fails, and control must be made to require the cancellation of the transfer business of A's account. This can ensure the correctness of the business. To complete this operation, a transaction is required. Put the decrease in account A funds and the increase in account B funds in the same transaction. Either all of them are executed successfully or all are cancelled, thus ensuring the security of the data. .

Four characteristics of transactions (ACID):

1) Atomicity: A transaction is a logical unit of work of the database, and it must be an atomic unit of work. , for its data modification, either all of them will be executed or none of them will be executed.

2) Consistency: When the transaction is completed, all data must be consistent. In the relevant database, all rules must be applied to transaction modifications to maintain the integrity of all data. (Example: transfer, the balance of two accounts is added, the value remains unchanged.)

3) Isolation: The execution of a transaction cannot be affected by other transactions.

4) Durability: Once a transaction is submitted, the operation of the transaction is permanently stored in the DB. Even if the database system encounters a failure, the operation of committing the transaction will not be lost.

How many types of transactions are there in Java?

There are three types of Java transactions: JDBC transactions, JTA (Java Transaction API) transactions, and container transactions.

The above is the detailed content of Why does JAVA use transactions?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template