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

When you call the get() method of a Future object and the task controlled by this object hasn't finished yet, the method is blocked until the task is finished. The Future interface provides another version of the get() method:

  • get(long timeout, TimeUnit unit): This version of the get method, if the result of the task isn't available, waits for the specified time. If the specified period of time passes and the result is still not available, it throws a TimeoutException exception. The TimeUnit class is an enumeration with the following constants: DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES, NANOSECONDS, and SECONDS.

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