This week's giveaway is in the Java in General forum.
We're giving away four copies of Java Challengers and have Rafael del Nero on-line!
See this thread for details.
Win a copy of Java Challengers this week in the Java in General 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

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

Teoman Se├žkin
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic