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

There's more...

The CompletionService class can execute Callable or Runnable tasks. In this example, you used Callable, but you could have also sent Runnable objects. Since Runnable objects don't produce a result, the philosophy of the CompletionService class doesn't apply in such cases.

This class also provides two other methods to obtain the Future objects of the finished tasks. These methods are as follows:

  • poll(): The version of the poll() method without arguments checks whether there are any Future objects in the queue. If the queue is empty, it returns null immediately. Otherwise, it returns its first element and removes it from the queue.
  • take(): This method, without arguments, checks whether there are any Future objects in the queue. ...

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