Why is UncaughtExceptionHandler not called by ExecutorService?

前端 未结 6 2093
你的背包
你的背包 2020-12-23 09:01

I\'ve stumbled upon a problem, that can be summarized as follows:

When I create the thread manually (i.e. by instantiating java.lang.Thread) the U

6条回答
  •  我在风中等你
    2020-12-23 10:00

    Because the exception does not go uncaught.

    The Thread that your ThreadFactory produces is not given your Runnable or Callable directly. Instead, the Runnable that you get is an internal Worker class, for example see ThreadPoolExecutor$Worker. Try System.out.println() on the Runnable given to newThread in your example.

    This Worker catches any RuntimeExceptions from your submitted job.

    You can get the exception in the ThreadPoolExecutor#afterExecute method.

提交回复
热议问题