Handling Exceptions for ThreadPoolExecutor

后端 未结 3 1395
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 03:00

I have the following code snippet that basically scans through the list of task that needs to be executed and each task is then given to the executor for execution.

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 04:05

    When you submit a task to the executor, it returns you a FutureTask instance.

    FutureTask.get() will re-throw any exception thrown by the task as an ExecutorException.

    So when you iterate through the List and call get on each, catch ExecutorException and invoke an orderly shutdown.

提交回复
热议问题