Stream parallel() / sequential() question.

Paul Sandoz paul.sandoz at oracle.com
Thu Apr 4 06:37:17 PDT 2013


In the tip parallel()/sequential() flip a bit to say how the complete pipeline is evaluated when the terminal operation commences.

Previously that was not the case: sequential() was a barrier if the upstream was parallel; and parallel() wrapped if the upstream was sequential.


On Apr 4, 2013, at 3:21 PM, Boaz Nahum <boaznahum at gmail.com> wrote:

> When I invoked parallel() or sequential() how backward it goes ?
> 
> Let me explain, I wrote a simple Consumer that report how many different
> threads used to run it:
> 
> source.
>            parallel().peek(new ThreadReporter("Segement 1 parallel")).
>            sequential().peek(new ThreadReporter("Segement 2 sequential")).
>            parallel().peek(new ThreadReporter("Segement 3 parallel")).
>            sequential().peek(new ThreadReporter("Segement 4
> sequential")).forEach((t) -> {});
> 

The complete pipeline will be evaluated sequentially since the final sequential() wins. Assuming the source stream is sequential the above would be equivalent to:

source.peek(...).peek(...).peek(...).peek(...).forEach(...)

Paul.


More information about the lambda-dev mailing list