Future and FutureTask both are available in java.util.concurrent package from Java 1.5.
Prerequisite: Future and callable
get() method of FutureTask acts like a latch as get() method waits or blocks till the task is completed. Once task completed, it returns the result or throws an ExecutionException. To avoid blocking, we can set the timeout in the get method.
In the output of the above program, we can notice that it doesn’t print anything for sometimes because get() method of FutureTask waits for the task to get completed and then returns the output object. We have used overloaded method to wait for the specified amount of time only for futureTask2. Also, notice the use of isDone() method to make sure the program gets terminated once all the tasks are executed.
As such there is no benefit of FutureTask but it comes handy when we want to override some of the Future interface methods and don’t want to implement every method of Future interface.