[concurrency-interest] Can Stream.close() be called at any time from any thread?

Dávid Karnok akarnokd at gmail.com
Fri Nov 2 09:25:15 EDT 2018


I couldn't find any specific description of whether Stream.close() can be
called at any time from any thread, or it has to be stricty in serialized
with an ongoing poll in it (of its iterator())?

 i.e., is generally the following safe/allowed with the Stream API?

Stream<String> stream = Files.lines(...);
Iterator<String> iterator = stream.iterator();


// Thread 1, repeatedly do
if (iterator.hasNext()) {

// Thread 2

(I already know how to work around if this is not allowed, just wanted to
know if I should workaround this concurrency problem).
Best regards,
David Karnok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20181102/9568e5ec/attachment.html>

More information about the Concurrency-interest mailing list