One of the advantages of the Executor framework is that it allows you to 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 the task. The Callable interface 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 Callable object and manage its state.
In this recipe, you will learn how to implement tasks that return a result and run them on an executor.