ThreadFactory threadFactory = new ThreadFactoryBuilder()
? ? ? ? ? ? ? ? .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 可以捕獲異常。