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. ...