Java Futures
Learn about the Future interface in Java.
Future interface
You may have heard of the java.util.concurrent.Future
interface in Java. Maybe you’ve even used
it.
This interface was added in Java 1.5, and it holds the result of an asynchronous computation. It contains methods to check if the asynchronous computation is complete or still in progress. It also includes methods that wait for the completion of the computation and block the call until the completion of the computation, and helps to retrieve the result of the computation.
There are many problems with this interface:
-
When using Java’s Future, we tend to loop on
isDone()
, which ties up the thread. Or we callget()
, which blocks the thread completely. -
ExecutorService#submit(x)
is used the most, which returns a ...