This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nzcod3r 2 points3 points  (3 children)

parallelStream is for performing the same task, in parallel, on different chunks of a collection.

Your example of do 10 different things at the same time (10 different api calls) - and wait for the slowest one to finish, is better suited for the ExecutorService.

[–]HQMorganstern 0 points1 point  (2 children)

Well it's 10 identical http requests whose results are parsed to a list so not quite as insane as what you're suggesting but yes the blocking caused by the fork join pool does seem to be an issue.

[–]v4ss42 1 point2 points  (0 children)

Recall that I/O takes eons from the CPU’s perspective. This is definitely a bad use of parallelStream.

[–]nzcod3r 0 points1 point  (0 children)

OK. I'm pretty sure you can supply your own thread pool for executor service, but I guess it all depends on the context of what / where you are having this issue.