Java 8 Streams API - Parallel Streams: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= {{Internal|Java 8 Streams API#Parallel_Streams|Parallel Streams}} =Overview= A ''parallel stream'' is a stream that splits its elements into multiple chunks, pro...")
 
Line 2: Line 2:


{{Internal|Java 8 Streams API#Parallel_Streams|Parallel Streams}}
{{Internal|Java 8 Streams API#Parallel_Streams|Parallel Streams}}
=TODO=
<font color=red>
Explain how data is partitioned.
</font>


=Overview=
=Overview=

Revision as of 19:45, 6 April 2018

Internal

Parallel Streams

TODO

Explain how data is partitioned.

Overview

A parallel stream is a stream that splits its elements into multiple chunks, processing each chunk with a different thread. This way the workload is automatically partitioned on all cores of a multicore processor.

A parallel stream is produced by a collection by invoking its parallelStream() method. An existing stream can be parallelized by invoking parallel() on the stream itself. Calling parallel() on a sequential stream does not imply any concrete transformation on the stream itself. Internally, a boolean flag is set to signal that the subsequent operations should be run in parallel. A parallel stream can be turned into a sequential stream by invoking sequential(). The last call on parallel() or sequential() affects the pipeline globally, it is not possible to have parts of the pipeline executed in parallel and parts of it executed sequentially.

Parallel stream implementations uses fork/join framework introduced in Java 7, specifically the ForkJoinPool.