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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Sybex Practice Tests 11 - Chapter 6, Question #72, Possibly Wrong Answer

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic