JavaDelegate thread scope

I’m using camunda embedded in spring boot and I noticed a strange behaviour of JavaDelegates when starting multiple processes.

I made a few test using two processes in which there are two service tasks that implement the same JavaDelegate that looks like this:

@Component
class MyDelegate implements JavaDelegate {

     private Expression field1;
     private Expression field2;

    @Override
    public void execute(DelegateExecution delegateExecution) {
        // code
    }
    
   /**
    * Getter and setter for field1 and field2
    */
}

I made a few tests using two process definitions.
I observed that if in the process1 both fields are given, the process engine retrieves them correcty, but if in the process2 field2, for instance, is not defined i.e. null, the process engine assigns the value from the previous process.

This led me to conclude that there is only one instance of each delegate for every process started.
However, as far as I understand it, each process is a separate thread, therefore in this case there is one resource shared between threads.

This is not the behaviour I expect from the process engine, so please could someone help me find a solution to segregate each delegate to its own process (thread)?
I understand Spring Boot scopes, but I’m wondering if the process enging provides a solution for scoping the delegates instead of letting Spring handle it.

Thank you.

Additional info:
I’m using camunda embedded in spring boot.

Hello @Leonardo_Chirivi,

Just tested what I thought was similar to your scenario and did not run into any issues.

Could you share your processes and your Java Delegate class to take a look at it?

Regards,

Are you using Delegate Expression or Java Class for implementation?