title: Stream works on sequential, but buggy in parallel mode
body: <p>Currently I am reading a <a href="https://rads.stackoverflow.com/amzn/click/com/1449370772" rel="nofollow noreferrer" rel="nofollow noreferrer">Java 8 Lambdas: Pragmatic Functional Programming</a> (very interesting and well written book, no adv.).</p>
  
  <p>After chapter 6 there is an exercise:</p>
  
  <blockquote>
    <p>The code multiplies every number in a list together and multiplies the
    result by
    5. This works fine sequentially, but has a bug when running in parallel.</p>
  </blockquote>
  
  <pre><code>public static int multiplyThrough(List&lt;Integer&gt; linkedListOfNumbers) {
      return linkedListOfNumbers.parallelStream()
                         .reduce(5, (acc, x) -&gt; x * acc);
  }
  </code></pre>
  
  <p>And solution:</p>
  
  <pre><code>public static int multiplyThrough(List&lt;Integer&gt; numbers) {
      return 5 * numbers.parallelStream()
                        .reduce(1, (acc, x) -&gt; x * acc);
  }
  </code></pre>
  
  <p>I don't understand why first approach is buggy in parallel mode and there is no explanation in the book.</p>
  
  <p>Please, explain.</p>