[b84 regression?] stream.parallel()/sequential() return the stream itself when they are not expected to (original) (raw)
Dmitry Bessonov dmitry.bessonov at oracle.com
Fri Apr 5 09:09:21 PDT 2013
- Previous message: [b84 regression?] stream.parallel()/sequential() return the stream itself when they are not expected to
- Next message: [b84 regression?] stream.parallel()/sequential() return the stream itself when they are not expected to
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Currently in the b84 implementation calling sequential() on a parallel stream results in returning the stream itself.
Moreover after calling sequential() on the parallel stream the original stream appears to be parallel no more:
Stream<String> stream = Arrays.asList("a", "b",
"c").parallelStream(); System.out.println(stream); System.out.println(stream.isParallel()); System.out.println(stream.sequential()); System.out.println(stream.isParallel());
the output will be
java.util.stream.ReferencePipeline$Head at 1f3c5b5 true java.util.stream.ReferencePipeline$Head at 1f3c5b5 false
-Dmitry
On 05.04.2013 19:46, Brian Goetz wrote:
Here is what the spec currently says:
/** * Produces an equivalent stream that is parallel. * If this stream is already parallel, may return itself. * *
This is an intermediate operation.
* * @return a parallel stream */ I believe this is what you are asking for? Sequential now says the same thing (as will unordered() in a few minutes.) On 4/5/2013 11:40 AM, Dmitry Bessonov wrote: Consider the following code sample:Stream stream = Arrays.asList("a", "b", "c").stream(); out.println("stream = " + stream); out.println("stream.isParallel() = " + stream.isParallel()); out.println("stream.parallel() = " + stream.parallel()); out.println("stream.parallel() = " + stream.parallel()); out.println("stream.parallel().isParallel() = " + stream.parallel().isParallel());
With b83 a "java.lang.IllegalStateException: Stream is already linked to a child stream" is thrown on attempt to double link a stream. With b84 the output is quite unexpected: stream = java.util.stream.ReferencePipeline$Head at 1f3c5b5 stream.isParallel() = false stream.parallel() = java.util.stream.ReferencePipeline$Head at 1f3c5b5 stream.parallel() = java.util.stream.ReferencePipeline$Head at 1f3c5b5 stream.parallel().isParallel() = true If it's not a regression then it looks like the spec for java.util.stream.BaseStream.parallel() deserves to be updated. The same issue takes place with parallel->sequential stream transformation so the spec for sequential() needs an update too. -Dmitry
- Previous message: [b84 regression?] stream.parallel()/sequential() return the stream itself when they are not expected to
- Next message: [b84 regression?] stream.parallel()/sequential() return the stream itself when they are not expected to
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]