Hello,
I found an issue in Chapter 7, page 369 when I decided to try out the code listed there.
Expected result: The program should take roughly 40 seconds to complete due to the Thread.sleep(10) with 4000 records.
Actual result: The program completes right away no matter what huge value you put in Thread.sleep() because the intermediate operations that call that method are not running.
After some head scratching, I tried replacing the count() method with different terminal operations, like forEach, and only then did I get the expected result. After looking at the API for the count() method I found the following:
An implementation may choose to not execute the stream pipeline (either sequentially or in parallel) if it is capable of computing the count directly from the stream source. In such cases no source elements will be traversed and no intermediate operations will be evaluated.
In this situation, there is no need to call the intermediate operations, so it doesn’t, and we don't get to see the effect of the Thread.sleep() method. So, the count() method should be replaced by some other terminal operation so that the intermediate operations run to call the processRecord() method with Thread.sleep().