Java Reference
In-Depth Information
Listing 11.11. Implementing the findPrices method with
CompletableFuture s
Note that you use two separate stream pipelines, instead of putting the two map operations one
after the other in the same stream-processing pipeline—and for a very good reason. Given the
lazy nature of intermediate stream operations, if you had processed the stream in a single
pipeline, you would have succeeded only in executing all the requests to different shops
synchronously and sequentially. This is because the creation of each CompletableFuture to
interrogate a given shop would start only when the computation of the previous one had
completed, letting the join method return the result of that computation. Figure 11.4 clarifies
this important detail.
 
Search WWH ::




Custom Search