<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">On 21/10/2025 12:57, Filip Egeric
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CANM=p+9Ya5jW9iyxPXXFfAvcEfc98PoiQi07diCGjMAfocmoSA@mail.gmail.com">
<div dir="ltr">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Have
you tried using a ThreadFactory factory instead? A custom<br>
ThreadFactory can be used to wrap all tasks so you get the<br>
acquire/release to limit concurrency.</blockquote>
<div><br>
</div>
<div>I haven't tried that. Would this be the optimal solution
with that approach?</div>
</div>
</blockquote>
<br>
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.<br>
<br>
-Alan<br>
</body>
</html>