We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Analysis Summary
Worth Noting
Positive elements
- This video provides a clear, concise explanation of how shared state and synchronization overhead impact the performance of parallel processing in Java.
Influence Dimensions
How are these scored?About this analysis
Knowing about these techniques makes them visible, not powerless. The ones that work best on you are the ones that match beliefs you already hold.
This analysis is a tool for your own thinking — what you do with it is up to you.
Transcript
Question 340. Why don't stateful operations play well with parallel streams? Short answer, because you need to share the state between the multiple threads. Less short answer. Some stream operations are said to be stateful. [music] That's the case for limit or skip. For instance, limit needs to interrupt your stream after it saw a given amount of elements. And if your stream is ordered, it should return the n first elements of the upstream, not n elements randomly [music] chosen. Even if your stream is not ordered, it still needs an internal [music] counter that is shared among the different threads that are computing your stream in parallel. This added synchronization can only slow down your computation, something you probably want to avoid. One last word, you need to be careful when you use parallel streams. In general, parallel stream will use all the cores of your CPU to conduct their operations and may slow down your other processes. When it comes to performance, as usual, measure, don't guess. Out.
Video description
Cracking the #Java #Coding #Interview - Question 340: Why do stateful operations don't play well with parallel streams? Watch all the questions here: https://youtube.com/playlist?list=PLzzeuFUy_Cngn3JZEXtu6G923y5v8y-8h