Structured Concurrency Feedback

Alan Bateman alan.bateman at oracle.com
Tue Oct 21 12:27:02 UTC 2025



On 21/10/2025 12:57, Filip Egeric wrote:
>
>     Have you tried using a ThreadFactory factory instead? A custom
>     ThreadFactory can be used to wrap all tasks so you get the
>     acquire/release to limit concurrency.
>
>
> I haven't tried that. Would this be the optimal solution with that 
> approach?

The try-finally needs to be after the acquire. Doing the acquire inside 
the try block means it will incorrectly release a permit if interrupted 
while waiting in acquire. As regards whether it is optimal then it's at 
the same level of granularity as what you had when doing it in the 
fork.  Limiting the concurrency at a finer grain, e.g. number of 
database connections in use, may be more optimal but it's may not be 
practical to do.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20251021/3a241d19/attachment.htm>


More information about the loom-dev mailing list