1.

What Is Callable And Future In Java Concurrency?

Answer»

Callable, an interface, was added in Java 5. It allows you to define a TASK to be completed by a THREAD asynchronously. The Callable interface has a call() method, since it is a generic interface so it can return any value (Object, String, Integer etc.) based on how it is initialized. Main feature of the call() method provided by Callable interface is that it can return value. 

Future interface - A Future represents the result of an ASYNCHRONOUS COMPUTATION. When you submit a callable task using the submit() method of the ExecutorService, Future object is returned.

Future PROVIDES methods to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation.

get() - get() method retrieves the result of the computation, blocking if necessary for the computation to complete.

Callable, an interface, was added in Java 5. It allows you to define a task to be completed by a thread asynchronously. The Callable interface has a call() method, since it is a generic interface so it can return any value (Object, String, Integer etc.) based on how it is initialized. Main feature of the call() method provided by Callable interface is that it can return value. 

Future interface - A Future represents the result of an asynchronous computation. When you submit a callable task using the submit() method of the ExecutorService, Future object is returned.

Future provides methods to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation.

get() - get() method retrieves the result of the computation, blocking if necessary for the computation to complete.



Discussion

No Comment Found