What is happening to all not finished tasks (threads) after joinUntil throws TimeoutException
Alan Bateman
alan.bateman at oracle.com
Mon Apr 7 07:40:00 UTC 2025
On 05/04/2025 01:18, Sergii Chekotylo wrote:
> The idea is to have a limited time for multiple tasks to finish.
> But if any of them didn’t finish - how to make sure that all of not-finished are interrupted and not using resources.
>
> Example:
>
> For one incoming http request I need to make 100 external calls to other systems to prepare data.
> And I need to have my own SLA no matter what is happening with other endpoints.
> If I’ll put joinUntill(“3s”) and my external calls are longer than that I should get TimeOutException.
> Which I can process in some way and give a result back.
> But what will happen to all unfinished tasks? Are they going to be interrupted or they will run till something else happened in each of them?
>
joinUntil will throw TimeoutException, and assuming you are using the
try-with-resources construct, then close will interrupt the threads
executing the unfinished subtasks and wait until they complete.
For your use-case then I assume you have extended STS and overridden
handleComplete to collect the subtasks that completed successfully. The
subtask will expose a method to get the completed subtasks.
-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20250407/dc2f2c6a/attachment-0001.htm>
More information about the loom-dev
mailing list