Spring-Service-事务中线程异常执行事务回滚的方式
来源:互联网 发布:网络电视直播pc版 编辑:程序博客网 时间:2024/05/19 02:24
方式一: 使用Callable, 利用Callable的返回值判断是否需要进行事务回滚
ExecutorService service = Executors.newCachedThreadPool(); Future<Integer> submit = service.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { System.out.println("bla bla ..."); return 5 * 3; } }); try { if (submit.get() == 15) { throw new RunTimeException("操作失败!"); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); }
方式二: 使用FutureTask
Callable<Integer> integerCallable = new Callable<Integer>() { @Override public Integer call() throws Exception { return 10; } }; ExecutorService executor = Executors.newCachedThreadPool(); FutureTask<Integer> futureTask = new FutureTask<>(integerCallable); try { Object o = executor.submit(futureTask).get(); throw new RuntimeException(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } executor.shutdown();
阅读全文
1 0
- Spring-Service-事务中线程异常执行事务回滚的方式
- Spring 代码中执行事务回滚
- Spring中发生异常的事务回滚问题
- Spring事务异常回滚
- Spring事务异常回滚
- Spring配置事务 service 异常捕获回滚问题
- Spring配置事务 service 异常捕获回滚问题
- Service层事务不能回滚的解决方式
- 关于Spring 代码中执行事务回滚
- spring事务的回滚
- Spring的事务回滚
- spring异常与事务回滚
- 异常类型 && spring事务回滚
- Spring事务和异常回滚
- Spring事务回滚和异常类
- spring 的异常驱动的事务回滚之谜
- Spring异常捕获而且回滚事务的方法
- 实验spring事务回滚与异常的关系
- Java工具包
- Longest Ordered Subsequence
- NLP with Deep Learning Lecture 2 笔记
- 远程来电流程分析---之二
- 笨办法学 Python · 续 练习 39:SQL 创建
- Spring-Service-事务中线程异常执行事务回滚的方式
- VC实现的全局键盘钩子
- Ext JS 继承
- SpringBoot20-springboot的Web开发-WebSocket
- Xilinx Altera FPGA中的逻辑资源(Slices VS LE)比较 前言 经常有朋友会问我,“我这个方案是用A家的FPGA还是X家的FPGA呢?他们的容量够不够呢?他们的容量怎么比较
- html5新特性:利用history的pushState等方法来解决使用ajax导致页面后退和前进的问题
- 平时学习时的记录||code blocks中“替换”的方法
- 并发编程(二):非线程安全集合类
- hdu 2846 Repository