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