一篇带你了解什么是事务及其原理
发表于 | 更新于
一.什么是事务事务: 指作为单个逻辑工作单元(Service方法)执行的一系列操作(数据库操作),要么全部执行,要么全部不执行。事务可以看做是一组任务,通常对应了一个业务方法,这些任务要么全部成功,要么全部失败。
本地事务有这么几个特征:
一次事务只连接一个支持事务的数据库(一般来说都是关系型数据库)
事务的执行结果保证[ACID]
会用到数据库锁
事务具有原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability)四个特性,简称 ACID,缺一不可。
二.原子性 Atomicity官方解释
Atomicity requires that each transaction be “all or nothing”: if one part of the transaction fails, then the entire transaction fails, and the database state is left unchanged. An atomic system must guarantee atom ...