当前位置:网站首页>线程池处理异常的方法
线程池处理异常的方法
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())
边栏推荐
- 图文详述Eureka的缓存机制/三级缓存
- [Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
- 18、分布式配置中心nacos
- 我的驾照考试笔记(3)
- [Multi-task learning] Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18
- Where should I prepare for the PMP exam in September?
- Ruijie switch basic configuration
- 【kali-信息收集】(1.4)识别活跃的主机/查看打开的端口:Nmap(网络映射器工具)
- latex paper artifact -- server deployment overleaf
- 卷积神经网络(CNN)mnist数字识别-Tensorflow
猜你喜欢

win10,在proe/creo中鼠标中键不能放大缩小

Get started quickly with MongoDB

New graduate students, great experience in reading English literature, worthy of your collection

数字孪生北京故宫,元宇宙推进旅游业进程

Buttons with good user experience should not have hover state on mobile phones

PROE/Croe如何编辑已完成的草图,让其再次进入草绘状态

Arthas 常用命令

【kali-信息收集】(1.5)系统指纹识别:Nmap、p0f

卷积神经网络(CNN)mnist数字识别-Tensorflow

Zheng Xiangling, Chairman of Tide Pharmaceuticals, won the "2022 Outstanding Influential Entrepreneur Award" Tide Pharmaceuticals won the "Corporate Social Responsibility Model Award"
随机推荐
MongoDB快速上手
实用新型专利和发明专利的区别?秒懂!
Redis 做网页UV统计
Does LabVIEW really close the COM port using VISA Close?
瀚高数据导入
解除360对默认浏览器的检测与修改
Custom command to get focus
如何写一个vim插件?
第59章 ApplicationPart内置依赖注入中间件
【kali-信息收集】(1.4)识别活跃的主机/查看打开的端口:Nmap(网络映射器工具)
【个人作品】记之-串口日志记录工具
idea插件generateAllSetMethod一键生成set/get方法以及bean对象转换
Redis does check-in statistics
"Torch" tensor multiplication: matmul, einsum
内网穿透 lanproxy部署
第55章 业务逻辑之订单、支付实体定义
专利检索常用的网站有哪些?
Interview Blitz 70: What are sticky packs and half packs?How to deal with it?
XSS靶场中级绕过
使用常见问题解答软件的好处有哪些?