Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31434

Re: .parallelStream()

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: .parallelStream()
Date Wed, 01 Apr 2015 10:19:09 -0400
Organization A noiseless patient Spider
Lines 36
Message-ID <mfgunb$rln$1@dont-email.me> (permalink)
References <parallelStream-20150401160329@ram.dialup.fu-berlin.de>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Wed, 1 Apr 2015 14:18:19 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="858a9d65d95f4ea4d355bd116aa2cdbf"; logging-data="28343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eO9SamodVym6KOA4BlqT1"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
In-Reply-To <parallelStream-20150401160329@ram.dialup.fu-berlin.de>
Cancel-Lock sha1:FMOQvlRC8g4UeiIyNQP9K9+Dmys=
Xref csiph.com comp.lang.java.programmer:31434

Show key headers only | View raw


On 4/1/2015 10:08 AM, Stefan Ram wrote:
>    I read somewhere that streams can be executed in parallel.
>
>    Somewhere else I read, that one needs to call
>    ».parallelStream()« for parallel execution.
>
>    So, do I get it right, that the JVM will never execute a
>    stream obtained by ».stream()« in parallel, even if it can
>    detect that this will be faster and yield the same outcome,
>    unless the programmer has explicitly enabled this via
>    ».parallelStream()«?

     Quoth the Javadoc for Collection (emphasis mine):

	default Stream<E> stream()
	Returns a *sequential* Stream with this collection as its
	source.

However, the sequential or parallel state of a Stream at the time
of creation need not be the final word; for some Streams it may be
possible to change the mode (before use, obviously).  The Javadoc
for BaseStream says (emphasis again mine):

	S parallel()

	Returns an equivalent stream that is parallel. May return
	itself, either because the stream was already parallel, or
	because the underlying stream state was *modified* to be
	parallel.

That is, it is possible that a Stream obtained from stream(), although
initially sequential, could become parallel later on.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

Re: .parallelStream() Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-01 10:19 -0400

csiph-web