Java Reference
In-Depth Information
7.1.1. Turning a sequential stream into a parallel one
You can make the former functional reduction process (that is, summing) run in parallel by
turning the stream into a parallel one; call the method parallel on the sequential stream:
In the previous code, the reduction process used to sum all the numbers in the stream works in a
way that's similar to what's described in section 5.4.1 . The difference is that the Stream is
internally divided into multiple chunks. As a result, the reduction operation can work on the
various chunks independently and in parallel, as shown in figure 7.1 . Finally, the same reduction
operation combines the values resulting from the partial reductions of each substream,
producing the result of the reduction process on the whole initial stream.
Figure 7.1. A parallel reduction operation
 
Search WWH ::




Custom Search