Executing Aysnchronous Tasks with CompletableFuture
Java SE 8 introduces class CompletableFuture (package java.util.concurrent
), which implements the Future
interface and enables you to asynchronously execute Runnable
s that perform tasks or Supplier
s that return values. Interface Supplier, like interface Callable
, is a functional interface with a single method (in this case, get
) that receives no arguments and returns a result. Class CompletableFuture
provides many additional capabilities that for advanced programmers, such as creating CompletableFuture
s without executing them immediately, composing one or more CompletableFuture
s so that you can wait for any or all of them to complete, executing code after a CompletableFuture
completes and ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.