As I see it, the obvious code, when using Java 8 Stream
s, whether they be "object" streams or primitive streams (that is, IntStream
and friends) would be to just use:
someStreamableResource.stream().whatever()
But then, quite a few "streamable resources" also have .parallelStream()
.
What isn't clear when reading the javadoc is whether .stream()
streams are always sequential, and whether .parallelStream()
streams are always parallel...
And then there is Spliterator
, and in particular its .characteristics()
, one of them being that it can be CONCURRENT
, or even IMMUTABLE
.
My gut feeling is that in fact, whether a Stream
can be, or not, parallel by default, or parallel at all, is guided by its underlying Spliterator
...
Am I on the right track? I have read, and read again, the javadocs, and still cannot come up with a clear answer to this question...