How to return results from asynchronous tasks to java?

I have a spring boot app that starts a very simple flowable process with just a start event, two groovy script tasks, a receive task and an end task: S -> G -> G -> R -> E. The two groovy scripts only sets two different variables using the code: execution.setVariable(“x”, “abc”); and execution.setVariable(“y”, “def”);

From my spring boot app I then make a pause using Thread.sleep and then I expect to be able to access the variable x using runtimeService.getVariables(pid).

This works perfectly when the two groovy script tasks have their asynchronous checkbox unchecked. However when I check it the variable cannot be accessed. I have also experimented with checking and unchecking the exclusive checkbox and also adding two parallell gateways but with no success.

What I like to do is basically to return the results from two tasks that are executed in two different threads?

I’m also uncertain how to know when the process has reached the receive task. That is why I temporarily use Thread.sleep. I have tried using an ExecuteDelegateListener but this listener has problem communicating with the code that started the process. The reason for the receive task is only to be able to access the variables and it helped when the script tasks where synchronous