I have a Camunda engine on a web server which uses variables that are specific to the execution of that process at request time. However, I have Java delegates which make external asynchronous calls and thus may sleep and resume at random times.
If I have multiple instances of a process being executed, what is the recommended way to make sure the threads do not share data?
Each process instance has its own data scope. To ensure responses from async service invocation get correlated back to the correct process instance you should use the businessKey (if possible, supported by the external system). The businessKey is a special process data used to search and identify process instances. It should be unique at least across instances of the same process definition, but Camunda does not enforce its uniqueness. Typical examples would be business ids such as application number, support request number or claim id.
The APIs and web portals offer dedicated support for the businessKey, so it is easier to work with than a regular process data.
I hope i understood your question correctly. Does this answer it?
A process might have finite number of activity types in which you can configure listeners and java delegates. So each activity(UserTask, ServiceTask, etc.) will have own instance of a delegates and listeners.
Lets say in both service tasks you’re updating a shared variable called “counter”, and when two service tasks executed in parallel, both the service tasks will try to synchronize at the join gateway, in that case if it’s not marked as exclusive it will throw an Optimistic locking exception.
For more details on asynchronous continuations refer the docs page.
If i am calling a Service task from different Process, is the Service Task/delegate thread-safe? Please give a look at the given example: Analytic Event Handler.bpmn (2.9 KB) AssetEventHandler.bpmn (2.7 KB) Process Event Handler.bpmn (2.7 KB)
In all the three process I am calling the same Service Task, in which I am setting some process Variables, do yout hink this is thread-safe? If not, how can i make it thread-safe!