O'Reilly logo

Java 9 Programming Blueprints by Jason Lee

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

Concurrent Java with a Future interface

One of the more common and popular APIs is the Future<V> interface. Future is a means to encapsulate an asynchronous calculation. Typically, the Future instance is returned by ExecutorService, which we'll discuss later. The calling code, once it has the reference to Future, can continue to work on other tasks while Future runs in the background in another thread. When the caller is ready for the results of Future, it calls Future.get(). If Future has finished its work, the call returns immediately with the results. If, however, Future is still working, calls to get() will block until Future completes.

For our uses, though, Future isn't the most appropriate choice. Looking over the non-functional requirements, ...

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