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.
Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!

Teoman Seçkin

Greenhorn
+ Follow
since Apr 25, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Teoman Seçkin

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.