Constructing parallel streams (original) (raw)

Remi Forax forax at univ-mlv.fr
Mon Dec 10 16:05:30 PST 2012


On 12/10/2012 05:01 PM, Joe Bowbeer wrote:

I can easily imagine a pipeline that has alternating sequential/parallel/sequential segments. Is there any reason to discourage a programmer from using the parallel/sequential methods to express this?

You don't need a method sequential() or parallel() for that, you can use into.

parallelStream.into(new ArrayList<>()).stream() is now sequential stream.into(new ArrayList<>()).parallel() is now parallel

and into() offer a better control on the intermediary data structure.

Rémi

On Dec 10, 2012 7:50 AM, "Brian Goetz" <brian.goetz at oracle.com_ _<mailto:brian.goetz at oracle.com>> wrote:

I don't like users being able to call parallel in the middle of the stream construction.

I don't love it either. The semantics are perfectly tractible, and the implementation is perfectly straightforward, but the performance is unlikely to be a win in most cases. (I mentioned earlier we would doc that this really should only be done at the head of the pipeline.) I propose to have an interface ParallelizableStream that allows to choose if the user want the sequential or the parallel stream upfront. Yeah, we investigated this direction first. Combinatorial explosion: IntParallelizableStream, etc. However, this could trivially become a dynamic property of streams (fits easily into the existing stream flags mechanism). Then only the head streams would have the property, and if you tried to do parallel() farther down the stream, we could ignore it or even throw ISE.



More information about the lambda-libs-spec-experts mailing list