Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java FutureTask completion check

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.

like image 565
RaceBase Avatar asked Aug 02 '12 11:08

RaceBase


1 Answers

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.

like image 169
Tomasz Nurkiewicz Avatar answered Nov 03 '22 06:11

Tomasz Nurkiewicz