What is the exact use of Future class in java.util.concurrent package?
Can we use it for Runnable interface instead of Callable interface which does not return any value, if yes, how?
I can see following method in java.util.concurrent.ExecutorService class
Since java.util.Runnable interface has only run() method and which cannot return any value , what will be Future<?> object's use here and what value Future object will catch/wrap/store in it for Runnable interface?
As specified in => FUTURE <= A Future represents the result of an asynchronous computation.As far as my understanding goes... The task you are trying to perform asynchronously, will go in as a Runnable task to e.g. a complex calculation . This will return a future object like . Now if you want to check whether the calculation (being done by the thread that has spawned for the runnable task) is over, you can call . However,this Thread (which is carrying out the invocation of get()) waits if necessary for the computation to complete, and then retrieves its result.
Please post if you have any particular problem, that needs a solution.
I gave an answer to that in the other copy of your question:
Jesper de Jong wrote:A Runnable indeed does not return a value, so for a Runnable, a Future is not that useful. It's still useful in that case to find out if the asynchronous task has failed with a runtime exception (get() would throw an ExecutionException in that case), or if the task has been executed, which you can check with the isDone() method of Future.