In our previous tutorial we have see about Java Thread Pool with Executor Framework and simple example as how its works. By using same Thread pool we will see about Callable interface working in this tutorial.
Normally we use Runnable interface to execute multi-threading in Java. Suppose if we need to get some output or return value from run() method then we can't use Runnable interface and it won't return any value. In case if we expect threads to return a computed result then we can use java.util.concurrent.Callable interface. The Callable object allows to return values after completion of each Thread execution. The Callable object uses generics to define the type of object which is returned and we will see simple example below as how its works along with Future.
If we submit a Callable object to an Executor the framework returns an object of type java.util.concurrent.Future. This Future object can be used to check the status of a Callable and to retrieve the result from the Callable. On the Executor you can use the method submit to submit a Callable and to get a future. To retrieve the result of the future use the get() method.