O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required