[External] : Re: A new build and a new structured concurrency API

Ron Pressler ron.pressler at oracle.com
Tue Nov 16 00:52:59 UTC 2021

> On 15 Nov 2021, at 23:33, Eric Kolotyluk <eric at kolotyluk.net> wrote:
> So, what is the rationale behind explicitly requiring 'join' or 'joinUntil'? Why can't close() at the end of the try-block implicitly deal with that?
> Cheers, Eric

That’s a good question!
The rational is to deal with a current limitation of AutoCloseable — it cannot distinguish between the case where the try block
terminates normally or exceptionally. This means that the implicit close would either have to cancel all tasks and then wait or
just wait, regardless of whether an exception has been thrown. If we choose the former, there can be situations where a piece
of code would just happen to work because the tasks happened to complete before close managed to cancel them, concealing a bug.
If we chose the latter, an exception in the owner would result in all tasks still being waited for, which could also be confusing.

Requiring an explicit join avoids these problems. If the language is changed to make AutoCloseable more flexible, this requirement
might be removed.

— Ron

More information about the loom-dev mailing list