Java FutureTask完成检查 [英] Java FutureTask completion check
问题描述
我已经检查了Oracle Java API,该API提供了一些信息,
I have checked Oracle Java API, which gives some info that FutureTask.isDone()
但是我需要检查任务是否已完成或终止并出现任何错误. 即使完成/终止,isDone()方法也将返回.但是我需要知道它是否由于某些问题而完成或终止.
but I need to check whether the task has completed or terminated with any error. isDone() method will return even if it completes/terminates. But I need to know whether it's completed or terminated due to some problem.
推荐答案
If the FutureTask
is done, call get()
afterwards (can be without any timeout, it should return immediately). It will either return some result or throw:
ExecutionException
-如果计算引发异常
ExecutionException
- if the computation threw an exception
ExecutionException.getCause()
将返回任务抛出的异常.
ExecutionException.getCause()
will return the exception thrown from your task.
这篇关于Java FutureTask完成检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!