Spring things you know you control characteristics

A transactional features.
Atomicity: the indivisibility emphasize affairs
consistency: to emphasize that before and after the execution of the transaction, the integrity of the data to be consistent
Isolation: executing a transaction should not be subject to interference from other transactions
persistence: Once the transaction end (commit / rollback) data on long-lasting hold to the database

Second, if you do not consider isolation, cause some security issues
reading problems
Dirty read: A transaction data read another transaction has not yet submitted a
non-repeatable read: A transaction update data read another transaction has been submitted, resulting in the current transaction multiple queries data inconsistencies
dummy read / phantom reads: read another transaction has a transaction insert data, resulting in the current transaction multiple times in the query results are inconsistent

Write problems
caused by two types of lost updates

Reading solve three problems caused.
Set the transaction isolation level
read uncommitted: read uncommitted. Dirty reads, non-repeatable reads, phantom reads can occur
read committed: Read Committed. Avoid dirty reads, non-repeatable reads and waste likely to occur
repeatable read: Repeatable Read. Prevent dirty reads and non-repeatable read, reading may occur dummy
serializable: serialized. Prevent dirty reads, non-repeatable read, generating dummy read

select @@ tx_isolation; see the isolation level
set session transaction isolation level level; Setting the isolation level

Four presentations reading problems
demo dirty reads
are open two windows dos AB
to view the isolation level select @@ tx_isolation two windows;
setting A window isolation level to read uncommitted set session transaction isolation level read uncommitted;
respectively in two window open transaction start transaction;
respectively two open windows dos AB
Update SET Money = Money Account - 1000 WHERE name = 'Sen';
Update Money = Money Account SET 1000 + WHERE name = 'Feng';
queries select data in the window A * from account; - a transaction data B is read transaction has not been submitted;

Demo avoid dirty reads, non-repeatable read presentation transmitted
respectively two open windows, AB
set the isolation level A window: read committed set session transaction isolation level read committed;
each transaction start transaction opening two windows;
complete the transfer at the B window
update account set money = money - 1000 where name = ' Sen';
Update Account SET Money = Money + 1000 WHERE name = 'Feng';
query select the A window from account; - prevent dirty reads
in the B window commit the transaction commit;
a query window again in the SELECT
from the Account; - transfer successful (non-repeatable read: a transaction update data read another transaction has been submitted, leading to inconsistent results of multiple queries.).

Prevent dirty reads and non-repeatable read presentation dummy read
respectively two open windows, AB
set the isolation level A window: repeatable read set session transaction isolation level repeatable read;
each start transaction in the transaction opening two windows;
complete window B transfer operations
update account set money = money - 1000 where name = ' Sen';
Update Account SET Money = Money + 1000 WHERE name = 'Feng';
a-window query SELECT from Account; - transfer without success: avoiding dirty reads .
submit window B transaction commit;
query select again in the A window
from account; - transfer without success: avoid non-repeatable read.

Avoid dummy read
respectively two open windows, AB
set A window isolation level: repeatable read set session transaction isolation level repeatable read;
each start transaction in the transaction opening two windows;
complete the insertion and insert into account values (null in window B 'Wang', 10000);
query operations in A select * from account; - no search results of any
committed transaction commit in window B; - A data window will be shown

Like the author of this article can give a point endorsed, look, will share Java-related articles every day! There are benefits presented from time to time, including the consolidation of learning materials, interview questions, such as source code ~ ~

Guess you like

Origin blog.51cto.com/14440597/2423280