mapConcurrent() with InterruptedException
Jige Yu
yujige at gmail.com
Fri Dec 27 18:00:55 UTC 2024
Hi Loom experts,
I was reading the mapConcurrent()
<https://github.com/openjdk/loom/blob/fibers/src/java.base/share/classes/java/util/stream/Gatherers.java>source
code yesterday and started to wonder what the behavior is when the thread
running the gatherer is being interrupted while waiting.
IIRC, it seems like interruption would have no effect until all elements
have been "integrated" and the code starts to run the finisher.
And when the finisher calls Future.get() on the first pending Future in the
window, it will throw InterruptedException, which will be caught,
re-interrupt the thread, and just **silently truncate the result**?
Is this the intended behavior? It means that if I'm looking at:
Stream.of(1, 2, 3).gather(mapConcurrent(i -> i * 2)).toList(), the result
can be any of [2], [2, 4] or [2, 4, 6], if there has been an interruption.
And if there is other blocking call after this line the code won't be able
to know that the result has been silently truncated.
I don't see unit tests to cover interrupted exception so I'd stand
corrected if I misread.
(I was curious as clearly that mapConcurrent() has no way to propagate
InterruptedException).
This is my first email in this mailing list so apologies for inappropriate
etiquette.
Happy Holidays!
Ben Yu,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20241227/aca3b2d3/attachment.htm>
More information about the loom-dev
mailing list