The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

tcadams289 (2) [Avatar] Offline
#1
Hi Guys,

Using this mutable IntSupplier means it can't be used in a parallel stream - correct?

You might want to make a point about side effects and mutating state in this section? I'm looking for some quick rules of thumb - good idea, bad idea when is it ok?

Thanks
Tom
raoul-gabriel.urma (37) [Avatar] Offline
#2
Re: Section 4.8 Fibonnancci IntSupplier
Hi Tom,

Yes you are right the IntSupplier with mutable state is not parallel safe.
E.g. If you run it with parallel() and compute the sum of first 10 elements:

IntStream.generate(fib).parallel().limit(10).sum();

You may get surprising different results at each run instead of the correct answer 143

I was even wondering whether I should include that example at all in the section to avoid this style. What do you think? Is it useful knowledge?

A side box with quick rules of thumb sounds like a great idea! We also have a section coming up in chapter 6 about quick rules of thumbs to run parallel streams efficiently.

Thanks,
Raoul