AnsweredAssumed Answered

Java service classes

Question asked by sheublein on Apr 23, 2013
Latest reply on Apr 25, 2013 by sheublein
Hi Forum,

I am currently trying to integrate Activiti with an application that is being developed at my company. I am still on a very low level regarding the understanding of Activiti and the interaction of its components but something struck me that I could not answer from reading the (btw excellent!) documentation or several developer blogs.

The Activiti implementation of Java service task in Activiti is very convenient for my Java project in order to execute custom Java code but I stumbled upon the following:

<b>Note: there will be only one instance of that Java class created for the serviceTask it is defined on. All process-instances share the same class instance that will be used to call execute(DelegateExecution). This means that the class must not use any member variables and must be thread-safe, since it can be executed simultaneously from different threads</b>

In my project I want to use a Java class to update a database with data from the user that has started the process. To do so I need to bring the name of the user along somehow and the class has to be called for each user (i.e. each process) with her own name specified.
Since the user guide states that all process-instances use the same class instance I wonder whether this is possible. I understand that the variable of the first process that contains the name would be overwritten as soon as the second process calls the Java class and if the first is not finished until then.

I am uncertain how to solve this and why Activiti does not support the construction of an own class instance for each process calling the same Java class. But maybe this is owed to a misunderstanding on my behalf as I am still quite new to Activiti and, frankly, also to Java.

A clarification would be greatly appreciated.

Best,

Steffen

Outcomes