您好,登錄后才能下訂單哦!
這篇文章主要介紹“Spring事務(wù)的隔離級別到底有幾種”,在日常操作中,相信很多人在Spring事務(wù)的隔離級別到底有幾種問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Spring事務(wù)的隔離級別到底有幾種”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
--什么是事務(wù)?
事務(wù)就是執(zhí)行操作要么全成功,要么全失敗,目的是保持數(shù)據(jù)的一致性
--事務(wù)管理的原理是什么?
AOP
--事務(wù)的特性?
ACID
--在Spring中進行事務(wù)管理需要配置哪些Bean?
事務(wù)管理器,事務(wù)定義Bean,事務(wù)切面,事務(wù)注解支持
--事務(wù)定義的目的是什么?
告知事務(wù)管理框架,如何進行事務(wù)管理。
--有幾種定義方式?
xml,注解
--可以定義些什么?
①xml方式:readOnly=“”
隔離級別
傳播行為
在什么樣的異常之下不回滾
定義什么樣的情況之下回滾
超時回滾
②注解方式@TransactionDefinition是一個接口
插入源碼
public interface TransactionDefinition {
int getPropagationBehavior();
int getIsolationLevel();
int getTimeout();
boolean isReadOnly();
String getName();
}
事務(wù)管理器
傳播行為7種
隔離級別?種
事務(wù)工作的隔離程度
事務(wù)的名字
返回是否只讀
點開@Transactional 找到 Isolation 一個枚舉類型,定義了幾種隔離級別
public enum Isolation {
/**
* Use the default isolation level of the underlying datastore.
* All other levels correspond to the JDBC isolation levels.
* @see java.sql.Connection
*/
DEFAULT(TransactionDefinition.ISOLATION_DEFAULT),
/**
* A constant indicating that dirty reads, non-repeatable reads and phantom reads
* can occur. This level allows a row changed by one transaction to be read by
* another transaction before any changes in that row have been committed
* (a "dirty read"). If any of the changes are rolled back, the second
* transaction will have retrieved an invalid row.
* @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED
*/
READ_UNCOMMITTED(TransactionDefinition.ISOLATION_READ_UNCOMMITTED),
/**
* A constant indicating that dirty reads are prevented; non-repeatable reads
* and phantom reads can occur. This level only prohibits a transaction
* from reading a row with uncommitted changes in it.
* @see java.sql.Connection#TRANSACTION_READ_COMMITTED
*/
READ_COMMITTED(TransactionDefinition.ISOLATION_READ_COMMITTED),
/**
* A constant indicating that dirty reads and non-repeatable reads are
* prevented; phantom reads can occur. This level prohibits a transaction
* from reading a row with uncommitted changes in it, and it also prohibits
* the situation where one transaction reads a row, a second transaction
* alters the row, and the first transaction rereads the row, getting
* different values the second time (a "non-repeatable read").
* @see java.sql.Connection#TRANSACTION_REPEATABLE_READ
*/
REPEATABLE_READ(TransactionDefinition.ISOLATION_REPEATABLE_READ),
/**
* A constant indicating that dirty reads, non-repeatable reads and phantom
* reads are prevented. This level includes the prohibitions in
* {@code ISOLATION_REPEATABLE_READ} and further prohibits the situation
* where one transaction reads all rows that satisfy a {@code WHERE}
* condition, a second transaction inserts a row that satisfies that
* {@code WHERE} condition, and the first transaction rereads for the
* same condition, retrieving the additional "phantom" row in the second read.
* @see java.sql.Connection#TRANSACTION_SERIALIZABLE
*/
SERIALIZABLE(TransactionDefinition.ISOLATION_SERIALIZABLE);
private final int value;
Isolation(int value) { this.value = value; }
public int value() { return this.value; }
}
源碼中指出:Spring事務(wù)的隔離級別有5種
DEFAULT:默認隔離級別,跟隨數(shù)據(jù)庫的隔離級別,Mysql默認采用
可重復(fù)讀,Oracle 默認采用讀已提交
READ_UNCOMMITTED:讀未提交,最低的隔離級別
READ_COMMITTED:讀已提交
REPEATABLE_READ:可重復(fù)讀
SERIALIZABLE:串行化,最高的隔離級別,事務(wù)依次執(zhí)行,性能差,
時間換空間的概念
--TransactionManager會有很多種嗎?
跟隨框架的不同,支持不同的事務(wù)管理
--什么是本地事務(wù)?什么是分布式事務(wù)?
本地事務(wù)就是數(shù)據(jù)庫事務(wù),分布式事務(wù)就是多數(shù)據(jù)源事務(wù)
--Spring事務(wù)管理接口
PlatformTransactionManager 開啟,提交,回滾
TransactionDefinition 事務(wù)定義
TransactionalStatus 事務(wù)狀態(tài)
到此,關(guān)于“Spring事務(wù)的隔離級別到底有幾種”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。