Java Lambdas and Parallel Streams by Michael Müller

Java Lambdas and Parallel Streams by Michael Müller

Author:Michael Müller
Language: eng
Format: epub, pdf
Publisher: Apress, Berkeley, CA


4 https://docs.oracle.com/javase/8/docs/api/java/util/Spliterator.html

© Michael Müller 2016

Michael MüllerJava Lambdas and Parallel Streams10.1007/978-1-4842-2487-8_9

9. Parallel Stream

Michael Müller1

(1)Brühl, Nordrhein-Westfalen, Germany

If by the usage of parallelStream the data can be processed correctly in parallel, you need to consider some ancillary conditions. In case of inobservance, either Java will prohibit parallel execution or you might get unexpected results. Use stateless lambda expressions.

State means you keep a value somewhere, for instance, in a variable. Now, if a future execution of the lambda expression depends on this value, the behavior of parallel execution may become non-deterministic. The result potentially becomes nonpredictable. If you’re lucky, the compiler prevents parallelism. Otherwise you will wonder about the results.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.