Reputation: 857
So I'm using the Guava's library Streams.stream(iterator) method to convert an iterator into a stream. And then I call parallel on that stream and perform some operations.
What I'm wonder is whether the converting of the iterator into a stream is done on the shared thread pool threads or beforehand.
Stream<MyItem> myItemStream = Streams.stream(myItemIterator);
myItem.parallel()...
Wondering because if the iterator conversion is done on the shared thread pool threads, that poses a problem for my use case in terms of thread safety.
Thanks!
Upvotes: 1
Views: 238
Reputation: 431
The call to Streams.stream(Iterator)
is just a convenience method around a call to the java StreamSupport
class:
public static <T> Stream<T> stream(Iterator<T> iterator) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false);
}
As such the Stream will use the common ForkJoinPool.
Upvotes: 1