Can Stream.close() be called at any time from any thread?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Can Stream.close() be called at any time from any thread?

JSR166 Concurrency mailing list
Hello,

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()) {
   handle(iterator.next());
}

// Thread 2
stream.close();

(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

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest