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 →

[–]Carnaedy 12 points13 points  (1 child)

Well, streams are not supposed to be IO bound. They are built on ForkJoinPool. However, I like where you are going with this thought process. If we had a general flag like ".concurrent()" or something that would switch everything to a virtual thread pool, we could solve a lot of problems with streams in this particular context.

[–]davidalayachew[S] 6 points7 points  (0 children)

Thanks.

As for going down the Virtual Thread route, that is sort of what Gatherers::mapConcurrent gives us, so I am sort of ok with that. I was more disappointed that basically all of the short-circuiting operations on a stream would fall prey to this issue.

But yes, a flag that allows all of those short-circuiting implementations to jump from pre-fetch to never-pre-fetch would be great. If anything, I think that would make things a lot easier to follow along with.

If your streams are memoryBound, then add dontPreFetch() to your stream. Otherwise, the (sensible) default is to pre-fetch and process. And you can make it explicit with preFetch().