Run the Service Tasks in another Thread and pass variables from one Thread to another

Hello,

I have the below flow which is working fine.
1)Rest End point is called ,then Send Order and Save Order Database and Rest Response is returned to the client in the same thread.This works fine .I am using Java Delegate Spring Boot App.

Now my requirement is to call Step 1,Step 2,Step 3 in another thread after the response is returned to the client.Also i need to pass some variable for "Save Order Database " to Step1.
How can i achieve and model it?

I’m not 100% sure, whether I understand your requirements.
But, to me, it sounds like a good example for message passing:
You can use two separate processes, one for <Start, Rest End…, Send Order, Save Order, End> another one for Step1–3.
The first process can send a message to start the second process. Within this message, you can pass required variables. If you furthermore set the “Asynchronous before” on the start event of the second process, it is executed in a separate threat:

To send a message from the java delegate of one process to another process, you can use the runtime service. More information can be found here:

1 Like

HI @StephanHaarmann

You can use two separate processes, one for <Start, Rest End…, Send Order, Save Order, End> another one for Step1–3.

Yes i need this.You are almost right
1.<Start, Rest End…, Send Order, Save Order, End> – will execute in a single thread.As soon as it reaches end .Response will return to Rest End .Also this part needs to pass some data to Step 1-3 after it ends only.
2. And then we will continue with Step 1-3.

But in your model you are calling Process 2 from Send Order .But i need to call Process 2 only when Process 1 ends.WIll ur model handle this case

Sure, you can change the model as follows:


A send event requires implementation.

1 Like

This works it seems