[Solved] Parallel streams in Java [closed]


From OCP : Oracle Certified Professional Java SE 8 Programmer || Study Guide : Exam 1z0-809

[…] Depending on the number of CPUs available in your environment
the following is a possible output of the code using a parallel stream
[…] Even better, the results scale with the number of processors.
Scaling is the property that, as we add more resources such as CPUs,
the results gradually improve. […]


To test it, you may want to use peek and print the Thread.currentThread()

int i = list.parallelStream()
            .peek(x -> System.out.println(Thread.currentThread()))
            .mapToInt(Integer::intValue)
            .max().getAsInt();

For me, using 4 processors, I get exactly four thread working on it.

solved Parallel streams in Java [closed]