Clarification on the instantiation of a JavaDelegate

Hello together,

I just wonder about some information in the docs. In the user guide it says, that “there will be only one instance of that Java class created for the serviceTask it is defined on”. From my personal experience and this post. I rather assume, that each time a process instance reaches a ServiceTask it will instantiate the corresponding JavaDelegate anew. Thus, am I right, that there is actually no need to make the JavaDelegates thread safe and that it is okay to use instance variables?

All the best

Hey @pekoson,

thanks for the report. You’re right a JavaDelegate is instantiated each time an activity is executed, which references this class. See this line of code.

I created a BUG Ticket to fix the corresponding documentation.

Thanks and best regards,
Chris

Couldn’t you reference the class via CDI (expression) and then set the class session via annotation? It’s been awhile since I verified this… But, I think there’s a way to use a singleton - a nice feature for managing things like globals, events, services (etc).

Latest versions of Wildfly should also now be able to support these shared resources. Multi-process/thread access can get a little tedious though (recommend “thread-safe” libraries/types).