How to catch exceptions in FutureTask

前端 未结 5 769
小蘑菇
小蘑菇 2020-12-06 04:42

After finding that FutureTask running in a Executors.newCachedThreadPool() on Java 1.6 (and from Eclipse) swallows exceptions in the Runnable

5条回答
  •  没有蜡笔的小新
    2020-12-06 05:02

    I have looked at the source code of FutureTask and could not find where setException is being called.
    There is an innerSetException method from FutureTask.Sync (inner class of FutureTask) that is being called in case of an Throwable being thrown by the run method. This method is also being called in setException.
    So it seams like the javadoc is not correct (or very hard to understand...).

提交回复
热议问题