How it works...

The first point to take into consideration to understand this example is the difference between the submit() method of the ThreadPoolExecutor class when you pass a Callable object as the parameter and the submit() method when you pass a Runnable object as the parameter. In the first case, you can use the Future object that this method returns to control the status of the task and to get its result. But in the second case, when you pass a Runnable object, you can only use the Future object that this method returns to control the status of the task. If you call the get() method of that Future object, you will get a null value.

To override this behavior, you have implemented the Task class. This class extends the FutureTask

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.