Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jmilktea/jtea
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyb committed Jul 29, 2024
2 parents 5f51e48 + 34940af commit 745ed9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
[java内省机制](https://github.com/jmilktea/jtea/blob/master/%E5%9F%BA%E7%A1%80/Java%E5%86%85%E7%9C%81%E6%9C%BA%E5%88%B6.md)
[并发工具类Phaser](https://github.com/jmilktea/jtea/blob/master/%E5%9F%BA%E7%A1%80/%E5%B9%B6%E5%8F%91%E5%B7%A5%E5%85%B7%E7%B1%BBPhaser.md)
[cglib FastClass机制](https://github.com/jmilktea/jtea/blob/master/%E5%9F%BA%E7%A1%80/cglib%20FastClass%E6%9C%BA%E5%88%B6.md)
[异常处理机制](https://github.com/jmilktea/jtea/blob/master/%E5%9F%BA%E7%A1%80/%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E6%9C%BA%E5%88%B6.md)

## jvm
[jvm常用参数](https://github.com/jmilktea/jtea/blob/master/jvm/jvm%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0.md)
Expand Down
10 changes: 5 additions & 5 deletions 基础/异常处理机制.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ submit方法则不同,它是通过FutureTask来执行任务,从源码可以

使用new Thread()创建线程时,可以调用setUncaughtExceptionHandler设置UncaughtExceptionHandler,但上面我们通过Executors.newFixedThreadPool,或者new ThreadPoolExecutor创建线程池时,就没有参数可以直接设置UncaughtExceptionHandler了,可以通过实现ThreadFactory接口来指定,我们使用guava可以这样创建:
```
new ThreadFactoryBuilder()
.setNameFormat(poolName + "-%d")
.setUncaughtExceptionHandler((t, e) -> {
//handle exception
}).build();
new ThreadFactoryBuilder()
.setNameFormat(poolName + "-%d")
.setUncaughtExceptionHandler((t, e) -> {
//handle exception
}).build();
```

**注意**,生产环境我们需要将异常堆栈输出到日志文件,所以尽管execute方法会抛出异常,但如果你没有对其进行捕获处理,也没有设置异常处理器,最终也还是丢失,我们就出现过因为线程池内任务没捕获异常没打印异常日志,排查问题非常麻烦。好了,本篇我们得出一个结论:**开启异步线程要进行异常捕获处理。**

0 comments on commit 745ed9a

Please sign in to comment.