Chapter 4. Getting Data from the Tasks – The Callable and Future Interfaces
In Chapter 2, Managing Lots of Threads – Executors, and Chapter 3, Getting the Maximum from Executors, we introduced the executor framework to improve the performance of concurrent applications and showed you how to implement advanced characteristics to adapt this framework to your needs. In these chapters, all the tasks executed by the executor were based on the Runnable interface and its run() method that doesn't return a value. However, the executor framework allows us to execute other kind of tasks that return a result based on the Callable and Future interfaces. In this chapter, we will cover the following topics:
- An introduction to the
CallableandFutureinterfaces - First example – a best-matching algorithm for words
- Second example – building an inverted index of a collection of documents