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.