One of the advantages of the Executor framework is that you can run concurrent tasks that return a result. The Java Concurrency API achieves this with the following two interfaces:
Callable: This interface has the
call()method. In this method, you have to implement the logic of a task. The
Callableinterface is a parameterized interface, meaning you have to indicate the type of data the
call()method will return.
Future: This interface has some methods to obtain the result generated by a
Callableobject and to manage its state.
In this recipe, you will learn how to implement tasks that return a result and run them on an executor.
The example of this recipe has been implemented ...