Java Reference
In-Depth Information
Figure 11.6. Combining two independent asynchronous tasks
11.4.5. Reflecting on Future vs. CompletableFuture
The last two examples in listings 11.16 and 11.17 clearly show one of the biggest advantages of
CompletableFutures over the other pre-Java 8 Future implementations. CompletableFutures
use lambda expressions to provide a declarative API that offers the possibility of easily defining
a recipe that combines and composes different synchronous and asynchronous tasks to perform
a complex operation in the most effective way. To get a more tangible idea of the code
readability benefits of Completable-Future, try to obtain the same result of listing 11.17 purely in
Java 7. Listing 11.18 shows you how to do it.
 
Search WWH ::




Custom Search