当前位置:网站首页>线程池处理异常的方法
线程池处理异常的方法
2022-08-01 20:22:00 【Q z1997】
线程池处理异常的方法
方法1:主动捉异常
ExecutorService pool = Executors.newFixedThreadPool(1);
pool.submit(() -> {
try {
log.debug("task1");
int i = 1 / 0;
} catch (Exception e) {
log.error("error:", e);
}
});
方法2:使用 Future
ExecutorService pool = Executors.newFixedThreadPool(1);
Future<Boolean> f = pool.submit(() -> {
log.debug("task1");
int i = 1 / 0;
return true;
});
log.debug("result:{}", f.get())
边栏推荐
- 小数据如何学习?吉大最新《小数据学习》综述,26页pdf涵盖269页文献阐述小数据学习理论、方法与应用
- 第59章 ApplicationPart内置依赖注入中间件
- 锐捷交换机基础配置
- 使用常见问题解答软件的好处有哪些?
- 【个人作品】记之-串口日志记录工具
- The graphic details Eureka's caching mechanism/level 3 cache
- 用户体验好的Button,在手机上不应该有Hover态
- Digital twin Beijing the imperial palace, yuan universe is the process of tourism
- 【kali-信息收集】(1.2)SNMP枚举:Snmpwalk、Snmpcheck;SMTP枚举:smtp-user-enum
- 终于有人把AB实验讲明白了
猜你喜欢
随机推荐
【Untitled】
An implementation of an ordered doubly linked list.
myid file is missing
【节能学院】智能操控装置在高压开关柜的应用
研究生新同学,牛人看英文文献的经验,值得你收藏
WhatsApp群发实战分享——WhatsApp Business API账号
Where should I prepare for the PMP exam in September?
漏刻有时文档系统之XE培训系统二次开发配置手册
Creo5.0 rough hexagon is how to draw
我的驾照考试笔记(4)
LTE time domain and frequency domain resources
二维、三维、四维矩阵每个维度含义解释
【Social Media Marketing】How to know if your WhatsApp is blocked?
【节能学院】数据机房中智能小母线与列头柜方案的对比分析
SIPp installation and use
大整数相加,相减,相乘,大整数与普通整数的相乘,相除
"Torch" tensor multiplication: matmul, einsum
17、负载均衡
"No title"
【多任务学习】Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18








