Stream and concurrent processing
All stream operations execute either sequentially or in parallel. They execute sequentially by default. To execute concurrently, a parallel stream must be created. The Stream
class uses a parallel
method, and the Collection
interface uses a parallelStream
method to create parallel streams.
The typical iterative loop in Java (such as the for
or while
loops) are serial in nature. That is, they are designed to execute sequentially and are not able to easily incorporate concurrent behavior.
Over the years, Java has introduced a number of improvements in how parallel behavior can be achieved. Each of these improvements has built upon the thread concept and frequently addresses specific concurrent approaches such as thread ...
Get Learning Java Functional Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.