Java FutureTask example
GIAN Tutorials
8:24 AM
FutureTask class has been introduced in JDK 5 with Executor Framework. FutureTask class is the concrete implementation of the Future object and provides methods for start and cancel the task.It also provides method to see if the computation is done or not. We can query FutureTask object and get the result of computation. If we call get method on FutureTask object, it is blocking call and returns once the computation is done. Let’s understand more with the example. Java FutureTask example: Let’s create a very simple example. Step 1: Create a Callable task named “MultiplyingTask.java”. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package org . arpit . java2blog ; import java . util . concurrent . Callable ; public class MultiplyingTask implements Callable { int a ; int b ; long sleepTime ; public MultiplyingTask ( int a , int b , long sleepTime ) {