unrdered()

Howard Lovatt howard.lovatt at gmail.com
Thu Apr 4 15:55:20 PDT 2013


See comments on sequential streams. A Limits interface could provide an unordered method that defaults to true and if you want to force ordered you override to return true. 

Sent from my iPad

On 05/04/2013, at 1:18 AM, Brian Goetz <brian.goetz at oracle.com> wrote:

>> Consider making forEach ordered by default, and relying on unordered()
>> to disable this.
> 
> We did consider this, and it is weird that this the only terminal that has unordered as its behavior, but I think the current behavior is right.
> 
> If someone does:
> 
>  seqStream.forEach(action)
> 
> They will expect that the action is performed sequentially in the calling thread.  If they do:
> 
>  seqStream.parallel().forEach(action)
> 
> I believe they will (reasonably) expect the action to happen in parallel across threads.  Constraining to encounter order gives up the vast majority of the parallelism.  I think if we did this people would say "parallel streams don't work."
> 
> 
> Separately, Paul quite correctly points out that back-propagating unordered from the terminal is a pain.  In:
> 
>  seqStream.parallel().distinct().forEach()
> 
> Here, since the forEach will be unordered, there's no point in doing the more expensive ordered processing for distinct.  This only shows up for parallel pipelines with stateful operations.  In that case, we can walk backwards injecting unordered, but have to stop when we hit a short-circuit operation.  (Though we could just omit this for now, its just an optimization.)


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