thread|thread UncaughtExceptionHandler
ThreadFactory threadFactory = new ThreadFactoryBuilder()
【thread|thread UncaughtExceptionHandler】.setNameFormat("httpclient-pool-%d")
.setDaemon(true)
.setUncaughtExceptionHandler((t, e)-> {
System.out.println("----------");
System.out.println(t.getName() +":"+ e.getMessage());
})
.build();
ExecutorService executorService = Executors.newFixedThreadPool(10, threadFactory);
executorService.submit() 时,setUncaughtExceptionHandler 无效,需要 future.get();
的方式获得异常。
executorService.excute() 时,setUncaughtExceptionHandler 可以捕获异常。
推荐阅读
- Java内存泄漏分析系列之二(jstack生成的Thread|Java内存泄漏分析系列之二:jstack生成的Thread Dump日志结构解析)
- 2019-08-16day20总结
- performSelectorOnMainThread:withObject:waitUntilDone:参数设置为NO或YES的区别
- c#中task与thread区别及其使用的方法示例
- 面试官再问你|面试官再问你 ThreadLocal,就这样狠狠 “怼” 回去!
- Netty|Netty 源码之 FastThreadLocal
- OC--多线程NSTheard
- RT-Thread|RT-Thread 入门学习笔记(vsnprintf来替代rt_vsnprintf来打印浮点)
- ThreadLocal源码学习
- 多线程工具ThreadLocal