The Executor framework allows programmers to execute concurrent tasks without creating and managing threads. You create tasks and send them to the executor. It creates and manages the necessary threads.
In an executor, you can execute two kinds of tasks:
- Tasks based on the Runnable interface: These tasks implement the
run()method that doesn't return any results.
- Tasks based on the Callable interface: These tasks implement the
call()interface that returns an object as a result. The concrete type that will be returned by the
call()method is specified by a generic type parameter of the
Callableinterface. To get the result returned by the task, the executor will return an implementation of the
Futureinterface for every task.
In previous chapters, you learned how to create executors, send tasks based on the
Runnable interface to it, and personalize the executor to adapt it to your needs. In this chapter, you will learn how to work with tasks based...