@Component in a class that inherits from a JavaDelegate

Dear all,
I am new to this community so forgive me if I am writing in the wrong section :sweat_smile:

In our implementation we have an abstract class that implements JavaDelegate which sets few instance variables (among all the DelegationExecution, I think this is bad designed but it was done like this and probably it will take some time to fix).

We noticed that when we introduced Spring and marked the child classes that implements the real activity behaviour with @Component a lots of concurrency issues started to happen. We use camunda:class when defining the activities with the .bpmn file and I was expecting to see NPEs as mentioned in other topics with @Autowired beans within the @Component but this is working fine.

I read somewhere that with a spring bean we should use delegateExpression because otherwise the DI will not work but itโ€™s not our case and I wonder how is this possible? What is really changing between the two ways? Can you point me to the classes that are dealing with it so that I can read the code and understand this mechanism better?

If you use Spring, all the delegates are singletons, i.e. they get instantiated just once and then used for all activity instances. If you save the execution object (which describes just one very special execution instance) as an instance variable in your (now singleton) delegates then itโ€™s no wonder that you get concurrency problems.