There's more...

The FutureTask class provides a method not included in the Future interface. It's the setException() method. This method receives a Throwable object as the parameter and when the get() method is called, an ExecutionException exception will be thrown. This call has an effect only if the set() method of the FutureTask object hasn't been called yet.

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.