一.示例 线程池内的线程并没有父子关系,所以不适合InheritableThreadLocal的使用场景 public class ThreadPoolInheritableThreadLocalDemo { // static ThreadLocal<String> threadLocal = new InheritableThreadLocal<>(); // static ExecutorService pool = Executors.newFixedThreadPool(…
一.Thread API: setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh) 首先要了解什么是Thread.UncaughtExceptionHandler,默认来说当线程出现未捕获的异常时,会中断并抛出异常,抛出后的动作只有简单的堆栈输出.如: public class ThreadTest{ public static void main(String[] args) throws Exception…