This week's giveaway is in the Spring forum. We're giving away four copies of liveProject: Protecting User Data with Spring Security and OAuth2 and have Laurentiu Spilca on-line! See this thread for details.
The question asks about output of the parallel stream code and the provided answer states that it is consistent across runs, the answer is C.
The answer states that the identity value is 1, it is applied to all list elements, (1+1), (1+2) and (1+3), then they are combined, the result is consistently 9.
Although Java seemingly solves this parallel stream problem consistently, I think it may not be that case when the total number of list elements exceeds the number of CPUs, or Java may decide to solve it as if it is a serial stream when there is 1 CPU available at that particular time, etc. Therefore I think it may give an answer between range [7,9]
Here I provide a sample code that breaks "consistently 9" explanation;
This code does not output 1001 (serial case) or 2000 (full parallel case as in the question) for me.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop