The official Oracle documentation says:
Note that you may lose the benefits of parallelism if you use operations like forEachOrdered with parallel s
I found stream().forEachOrdered() is ~50% faster than its parallel counterpart. Plus the parallel one uses at least one thread from common fork-join thread pool, which is - one less thread for other parallel streams running in JVM.
public static void main(String[] args) {
long start = System.currentTimeMillis();
IntStream.range(0,10000000).parallel().forEachOrdered(i -> {
//System.out.println(Thread.currentThread().getName());
int p = 1 * 1 ;
});
System.out.println((System.currentTimeMillis() - start));
}