My Workflow has 2 components. One that can be executed parallely by multiple thread (here i’m invoking child workflows) and the second that needs to be thread safe (Here I’m analyzing the outpupts of childworkflows).
How to ensure oneThreadAtaTime function is executed by only one thread at a time? Is there a way in temporal as i’m not allowed to use native java thread operations inside workflows.
Note : parallelBlock() and oneThreadAtaTime() are coupled together. They can’t be separated so as to apply Async.function just on the parallelBlock
What prevents the 3 threads from executing the Workflow.await(()->!oneAtATime); at the same time?
If they do so, oneAtATime will be false for all the three. And all three will endup executing analyzeOutputsAndTakeDecissions() function.
Are we making the assumption that, as all the childworkflows will be executed by a single thread, there is no chance of all the 3 workflows completing at the same time?
Temporal uses cooperative multithreading. So only one thread is executing at a time until it is blocked on some Temporal SDK API like await. So in your example, it is not possible for all three threads to get unblocked at the same time and the function analyzeOutputsAndTakeDecissions will be executed by only one of them at the time.