cancel
Showing results for 
Search instead for 
Did you mean: 

FormService.submitStartFormData thread safety issue

kaech
Champ in-the-making
Champ in-the-making
Hi,

We are developing an application in which many processes are started from multiple threads in parallel via FormService.submitStartFormData().
We start different processes with different sets of form properties.
Somtimes it happens that submitStartFormData starts the wrong process. The result is that the process gets the wrong properties which causes the process to fail. The more processes we start in parallel, the more threads we have. This increases the likeliness of the issue.
When we sychronize the call to processInstance.start in org.activiti.engine.impl.cmd.SubmitStartFormCmd.execute it works without problems.
Like this:

synchronized(SyncObj.class){
  processInstance.start();
}

It seems that ExecutionEntity.start is not thread safe.
Is that true?
5 REPLIES 5

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
How do you start processes…? Example code?

kaech
Champ in-the-making
Champ in-the-making
Hi Ronald,

we have a Web Service implemented with CXF.
In the Web Service request we do the following:

String processKey = .. obtain key from request
ProcessDefinition pd = activitiRepositoryService.createProcessDefinitionQuery().processDefinitionKey(processKey).latestVersion().singleResult();
String businessKey = UUID.randomUUID().toString();
Map<String, String> formVariables = obtain properties from request
activitiformService.submitStartFormData(pd.getId(), businessKey, formVariables);

We have two processes with one version each deployed. So all in all two procedure definitions in the database.
submitStartFormData is called with the correct parameters.

From what I see processInstance.start() in org.activiti.engine.impl.cmd.SubmitStartFormCmd.execute is called properly.

When we start at least two threads and thread 2 calls start() before thread 1 start() finished, the problem occurs.

Example:

Thread 1, Process A, Properties A
Thread 2, Process B, Properties B

Result:

Thread 1, Process B, Properties A
Thread 2, Process B, Properties B

Cheers
Kaech

frederikherema1
Star Contributor
Star Contributor
I've just double-checked in the code, and a submitStartFormCommand instance is completely isolated from other instances. The variables are submitted to an ExecutionEntity, created locally in the execute method. Is it possible to create a unit-test highlighting this issue (perhaps with waiting-service tasks or something to simulate waits/threading issues)?

udoderk
Champ in-the-making
Champ in-the-making
Are you use the Activiti 5.8 or Activiti 5.11 engine?

kaech
Champ in-the-making
Champ in-the-making
@udoderk: I am using 5.10

@frederikheremans: Unfortunately I don't have time at the moment. The synchonization hack works for the time being. I will create something, if I  have more time.