Summary of Java things basics

Source: Internet
Author: User
Tags try catch

1. What is a thing?

A thing is a logical operation in which each element of the operation is either successful or all fails. For example, a bank transfer process is considered a thing, and the transfer process and the transfer process require all success or failure, by committing things or rolling back things.

2. The role of Things

Ensure that either all succeeds in a set of operations, or all fails.

3. The nature of Things (important)

ACID

Atomicity atomicity: Refers to the operation of a thing as an indivisible work unit or all success or failure.

Consister consistency: The integrity of the data before and after the thing is consistent (for example, bank transfer, how much less money to transfer the account, how much money is needed to transfer to the account)

Isolation isolation: When multiple users have concurrent access, they do not affect each other

Durability persistence: means that once a thing is committed, he changes the database permanently.

4. Manipulation of Things

A:mysql things Operations

Open Things start transaction

Commit a thing commit

Rolling back things rollback

Note: Things are only executed if they are rolled back or submitted

There are two ways of managing things in MySQL

1) Manual Submission

Start transaction;        SQL statement operation database; Commit

2) Automatic submission

Set autocommit = 0; ----0:off   1:on

B:JDBC Things---Manipulated by connection object methods

Open things: Connection objects. Setautocommit=false;

Commit a thing: Connectin object. commit ();

Rollback thing: Connection object. Rollback ();

Note: Smooth the code of the thing operation into the try catch, and roll back the thing when the exception occurs

C:dbutils manipulating Things

Open things: Conn.setautocommit=false

Submit things: Dbutils.commitandclose (conn)

Rolling back things: Dbutils.rollbackandclose (conn)

Note: The parameter is not passed when new Query ()

5. Concurrent access issues and solutions

Concurrent access issues:

Dirty read: Thing a reads the data that things B is raising prices

Non-repeatable READ: When thing A is not yet committed, but thing B has committed a change to the database, the data for a repeating read database is the modified data of thing B (because thing a does not commit the data, it should read data repeatedly when it is opened)

Virtual/Phantom read: Similar to non-repeatable read. More focused on reading inconsistent data.

WORKAROUND:----Set the isolation level of the database

1.read uncommitted read not submitted;

2.read committed Read Committed: can solve dirty read problem

3.repeatable read repeatability: Resolves problematic dirty reads and non-repeatable reads

4.serializable serialization can execute only one thing at a time, the equivalent of a single thread in a thing

Safety Performance Comparison:

Safety:

Serializable > Repeatable READ > Read committed > READ UNCOMMITTED

Performance

Serializable < REPEATABLE Read < Read Committed < READ UNCOMMITTED

# # # #常见的查询操作

The cmd command queries the isolation level of the current thing: select @ @tx_isolation;

Sets the isolation level of the current thing: Set session transaction ISOLATION level isolation;

Check whether the current is autocommit: show variables like '%commit% ';

Summary of Java things basics

Related Article

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.