Spring 7大事务传播模型
REQUIRED
/** * Support a current transaction, create a new one if none exists. * Analogous to EJB transaction attribute of the same name. * <p>This is the default setting of a transaction annotation. */
必须有一个事务,如果当前已存在则用当前的,如果不存在则新建一个事务
SUPPORTS
/** * Support a current transaction, execute non-transactionally if none exists. * Analogous to EJB transaction attribute of the same name. * <p>Note: For transaction managers with transaction synchronization, * PROPAGATION_SUPPORTS is slightly different from no transaction at all, * as it defines a transaction scope that synchronization will apply for. * As a consequence, the same resources (JDBC Connection, Hibernate Session, etc) * will be shared for the entire specified scope. Note that this depends on * the actual synchronization configuration of the transaction manager. * @see org.springframework.transaction.support.AbstractPlatformTransactionManager#setTransactionSynchronization */
使用当前事物,如果当前则以无事务模式运行
MANDATORY
/** * Support a current transaction, throw an exception if none exists. * Analogous to EJB transaction attribute of the same name. */
表示强制需要一个事务,如果不存事务则抛出异常
REQUIRES_NEW
/** * Create a new transaction, and suspend the current transaction if one exists. * Analogous to the EJB transaction attribute of the same name. * <p><b>NOTE:</b> Actual transaction suspension will not work out-of-the-box * on all transaction managers. This in particular applies to * {@link org.springframework.transaction.jta.JtaTransactionManager}, * which requires the {@code javax.transaction.TransactionManager} to be * made available it to it (which is server-specific in standard Java EE). * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager */
每次都创建一个新的事务,如果当前存在事务则挂起当前事务运行新事务,两个事务互相独立,新事物回滚也不会影响外部事务
NOT_SUPPORTED
/** * Execute non-transactionally, suspend the current transaction if one exists. * Analogous to EJB transaction attribute of the same name. * <p><b>NOTE:</b> Actual transaction suspension will not work out-of-the-box * on all transaction managers. This in particular applies to * {@link org.springframework.transaction.jta.JtaTransactionManager}, * which requires the {@code javax.transaction.TransactionManager} to be * made available it to it (which is server-specific in standard Java EE). * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager */
已非事务模式运行,如果当前存在事务则挂起当前事务
NEVER
/** * Execute non-transactionally, throw an exception if a transaction exists. * Analogous to EJB transaction attribute of the same name. */
从不需要事务,如果当前存在事务则抛出异常,刚好与 MANDATORY 相反
NESTED
/** * Execute within a nested transaction if a current transaction exists, * behave like PROPAGATION_REQUIRED else. There is no analogous feature in EJB. * <p>Note: Actual creation of a nested transaction will only work on specific * transaction managers. Out of the box, this only applies to the JDBC * DataSourceTransactionManager when working on a JDBC 3.0 driver. * Some JTA providers might support nested transactions as well. * @see org.springframework.jdbc.datasource.DataSourceTransactionManager */
嵌入式事务模式,与PROPAGATION_REQUIRED相似,如果没有就新建,如果有适用当前事务,但是NESTED具体当前事务多个保存点,可以部分回滚。仅适用于JDBC事务管理,内部可以独立回滚并且不影响外部。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Phalcon+Swoole 无侵入解决方案 PhaService
Phalcon有着强大的性能同时又具备完整的MVC模式, Swoole也具备在Phalcon之外的其他能力,如果把两者无缝的结合, 一定是一个不错的案例. 所以本项目 同时支持 Nginx+Phalcon 与 Swoole+Phalcon, 如果使用Nginx做负载均衡,可以做到无缝衔接,有Nginx+php-fpm的稳定, 同时也能享受Swoole对于API的超高性能. 本案例可以作为系统服务使用, 也可以做Restful开发使用,作为Web使用更是毫无问题. 使用 wrk 做的的压测, 在MBP上的结果: wrk -c10000 -d10s --latency http://127.0.0.1:8080/testRunning 10s test @ http://127.0.0.1:8080/test 2 threads and 10000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 38.66ms 50.01ms 266.35ms 81.83% Req/Sec 12.97k 1.54k 16.65k 88.17...
- 下一篇
装饰器
谈装饰器前,还要先要明白一件事,Python 中的函数和 Java、C++不太一样,Python 中的函数可以像普通变量一样当做参数传递给另外一个函数,例如: def foo(): print("foo") def bar(func): func() bar(foo) 正式回到我们的主题。装饰器本质上是一个 Python 函数或类,它可以让其他函数或类在不需要做任何代码修改的前提下增加额外功能,装饰器的返回值也是一个函数/类对象。它经常用于有切面需求的场景,比如:插入日志、性能测试、事务处理、缓存、权限校验等场景,装饰器是解决这类问题的绝佳设计。有了装饰器,我们就可以抽离出大量与函数功能本身无关的雷同代码到装饰器中并继续重用。概括的讲,装饰器的作用就是为已经存在的对象添加额外的功能。 先来看一个简单例子,虽然实际代码可能比这复杂很多: def foo(): print('i am foo') 现在有一个新的需求,希望可以记录下函数的执行日志,于是在代码中添加日志代码: def foo(): print('i am foo') logging.info("foo is running")...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2整合Redis,开启缓存,提高访问速度
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS8编译安装MySQL8.0.19
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- Red5直播服务器,属于Java语言的直播服务器