这篇文章主要介绍“Spring事务的隔离级别到底有几种”,在日常操作中,相信很多人在Spring事务的隔离级别到底有几种问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Spring事务的隔离级别到底有几种”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
--什么是事务?
事务就是执行操作要么全成功,要么全失败,目的是保持数据的一致性
--事务管理的原理是什么?
AOP
--事务的特性?
ACID
--在Spring中进行事务管理需要配置哪些Bean?
事务管理器,事务定义Bean,事务切面,事务注解支持
--事务定义的目的是什么?
告知事务管理框架,如何进行事务管理。
--有几种定义方式?
xml,注解
--可以定义些什么?
①xml方式:readOnly=“”
隔离级别
传播行为
在什么样的异常之下不回滚
定义什么样的情况之下回滚
超时回滚
②注解方式@TransactionDefinition是一个接口
插入源码
public interface TransactionDefinition {
int getPropagationBehavior();
int getIsolationLevel();
int getTimeout();
boolean isReadOnly();
String getName();
}
事务管理器
传播行为7种
隔离级别?种
事务工作的隔离程度
事务的名字
返回是否只读
点开@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事务的隔离级别有5种
DEFAULT:默认隔离级别,跟随数据库的隔离级别,Mysql默认采用
可重复读,Oracle 默认采用读已提交
READ_UNCOMMITTED:读未提交,最低的隔离级别
READ_COMMITTED:读已提交
REPEATABLE_READ:可重复读
SERIALIZABLE:串行化,最高的隔离级别,事务依次执行,性能差,
时间换空间的概念
--TransactionManager会有很多种吗?
跟随框架的不同,支持不同的事务管理
--什么是本地事务?什么是分布式事务?
本地事务就是数据库事务,分布式事务就是多数据源事务
--Spring事务管理接口
PlatformTransactionManager 开启,提交,回滚
TransactionDefinition 事务定义
TransactionalStatus 事务状态
到此,关于“Spring事务的隔离级别到底有几种”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。