In our examples, so far, we used the execute() method of the ExecutorService interface to start a thread. In fact, this method comes from the Executor base interface. Meanwhile, the ExecutorService interface has other methods (listed in the previous Using pool of threads section) that can start threads and get back the results of thread execution.
The object that brings back the result of the thread execution is of type Future—an interface that has the following methods:
- V get(): Blocks until the thread finishes; returns the result (if available)
- V get(long timeout, TimeUnit unit): Blocks until the thread finishes or the provided timeout is up; returns the result (if available)
- boolean isDone(): Returns true if the thread has finished
- boolean cancel(boolean mayInterruptIfRunning): Tries to cancel execution of the thread; returns true if successful...