Java Reference
In-Depth Information
Chapter 11. CompletableFuture: composable
asynchronous programming
This chapter covers
Creating an asynchronous computation and retrieving its result
Increasing throughput using non-blocking operations
Designing and implementing an asynchronous API
Consuming asynchronously a synchronous API
Pipelining and merging two or more asynchronous operations
Reacting to the completion of an asynchronous operation
In recent years, two trends are obliging us to rethink the way we write software. The first trend
is related to the hardware on which we run our applications, and the second trend concerns how
applications are structured and particularly how they interact with each other. We discussed the
impact of the hardware trend in chapter 7 . We noted that since the advent of multicore
processors, the most effective way to speed up your applications is to write software that's able
to fully exploit the multicore processors. You saw that this is possible by splitting large tasks and
making each subtask run in parallel with the others; you also learned how the fork/join
framework (available since Java 7) and parallel streams (new in Java 8) allow you to accomplish
this in a simpler and more effective way than by directly working with threads.
The second trend reflects the increasing availability and use by applications of internet services
accessible through public APIs, made available by known providers such as Google (for example,
localization information), Facebook (for example, social information), and Twitter (for example,
news). Nowadays it's relatively rare to develop a website or a network application that works in
total isolation. It's far more likely that your next web application will be a mash-up: it will use
content from multiple sources and aggregate it to ease the life of your end users.
For instance, you might like to provide the collective sentiment about a given topic to your
French users; to do this you could ask the Facebook or Twitter API for the most trending
comments about that topic in any language and maybe rank the most relevant ones with your
internal algorithms. Then you might use Google Translate to translate them into French, or even
Google Maps to geolocate where their authors live, and finally aggregate all this information and
display it on your website.
 
Search WWH ::




Custom Search