RFR 8027316 Distinct operation on an unordered stream should not be a barrier
Paul Sandoz
paul.sandoz at oracle.com
Wed Oct 30 17:14:52 UTC 2013
On Oct 30, 2013, at 5:54 PM, Henry Jen <henry.jen at oracle.com> wrote:
> Looks good to me.
>
Thanks.
> In the test,
>
>> Integer one = Stream.iterate(1, i -> i + 1).unordered().parallel().distinct().findAny().get();
>> assertEquals(one.intValue(), 1);
>
> The implementation is probably make sure this will return 1, but is that what we spec to do? I sort of think it can have various values depends on how many working threads and their scheduling.
Stream.iterate produces an ordered sequence of x, f(x), f(f(x)), f(f(f(x))), etc.
Internally the stream is constructed from a spliterator derived from an iterator. Although we don't explicitly say it the unary function is never called concurrently: applying the function to one element happens-before applying the function to subsequent elements, but for any given element, the function may be applied in whatever thread the library chooses [*].
Paul.
[*] copied from Stream.forEachOrdered.
More information about the core-libs-dev
mailing list