Problems in the concurrency of things, as well as pessimistic locks and optimistic locking problems

Source: Internet
Author: User

problems that occur in the concurrency of things

A) dirty reads (Dirty read), read UNCOMMITTED data.

No committed data was read for another transaction

b) Non-repeatable read (Nonrepeatable Read)

In the same thing, it is different to read 2 times before and after. (There may be a read process in which another transaction modifies the data)

c) Phantom Read (Phantom Read)

In the course of your reading, another transaction inserts a new data into it, affecting the results you read.

Insert and delete operations (here The general database locks are not allowed to be updated, deleted and inserted when possible)

Java.sql.connection has the same level of isolation and hibernate as the business.

A) read-uncommitted: capable of reading uncommitted data 3 will appear

b) read-committed: You can't limit the repetition read

c) repeateable read: The underlying is the locking mechanism.

d) Serializable: No matter how many transactions come, you give me one of the execution, there will be problems. There must be no more.

pessimistic lock, optimistic locking mechanism

In order to consider the efficiency of concurrency, we set it to read committed, but what I need to solve is non-repeatable read, in Hibernate there are two ways to solve

Pessimistic lock

AccountA = (account) session.load (Account.class, 1, Lookmode. upgrade);//upgrade

select* from ... for update

The underlying use of the database lock mechanism (only after I read the other to be able to update)

optimistic Lock

Version of the mechanism, it does not lock, with a version field. The table field adds itself, and then the update is hibernate-updated.

The corresponding table

Isolation level

Dirty Reads (Dirty read)

Non-repeatable read (Nonrepeatable Read)

Phantom Read (Phantom Read)

Unread (Read UNCOMMITTED)

possible

possible

possible

Read submitted (committed)

No way

possible

possible

REPEATABLE READ (Repeatable Read)

No way

No way

may be

Serializable (Serializable)

No way

No way

No way






This is a problem that occurs when a transaction is not supported. Generally do not need to consider







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.