Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 31
    Good answer. I would add that if you have a massive amount of items to process, that only increases the thread coordination issues; it's only when processing of each items takes time and is parallelizable that parallelization might be useful. Commented Apr 8, 2014 at 16:12
  • 23
    @WarrenDew I disagree. The Fork/Join system will simply split the N items into, for example, 4 parts, and process these 4 parts sequentially. The 4 results will then be reduced. If massive really is massive, even for fast unit processing, parallelization can be effective. But as always, you have to measure. Commented Apr 8, 2014 at 16:49
  • i have a collection of objects that implement Runnable that I call start() to use them as Threads, is it ok to change that to using java 8 streams in a .forEach() parallelized ? Then i'd be able to strip the thread code out of the class. But are there any downsides? Commented Jun 5, 2016 at 18:56
  • 1
    @JBNizet If 4 parts pocess sequentially, then there is no difference of it being process parallels or sequentially know? Pls clarify Commented Jul 27, 2016 at 16:31
  • 5
    @Harshana he obviously means that the elements of each of the 4 parts will be processed sequentially. However, the parts themselves may be processed simultaneously. In other words, if you have several CPU cores available, each part can run on its own core independently of the other parts, while processing its own elements sequentially. (NOTE: I don't know, if this is how parallel Java streams work, I'm just trying to clarify what JBNizet meant.) Commented Nov 17, 2016 at 15:37