문제

I have checked Oracle Java API, which gives some info that FutureTask.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 - if the computation threw an exception

ExecutionException.getCause() will return the exception thrown from your task.

다른 팁

Why not call FutureTask.get() ?

This will return the result or throw an exception containing the exception originally thrown/caught. If the task hasn't complete dit will block, and you have the option to provide a timeout.

I would normally expect clients simply to call get() on each FutureTask in turn once created, rather than poll isDone().

When isDone() return true you would like to get result by calling get() method to check the result of execution. get() operation can throw ExecutionException, which consist of cause, where you can find a problem.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top