DontPanic
DontPanic

Reputation: 1367

Async service tasks on clustered applications with Activiti engine

I have 2 applications running on the same database. Both of them start activiti processes like this:

for (i = 0; i < msgNbr; i++) {
    Map<String, Object> dataMap = Data.prepareData(testOptions);
    runtimeService.startProcessInstanceByKey("asyncTransferProcess", dataMap);
}

First service task in processes that are starting is async:

<serviceTask id="serviceTask1" name="ServiceTask1" activiti:exclusive="true"
    activiti:class="com.test.activiti.async.ServiceTask1"></serviceTask>

Async executors configuration:

<property name="asyncExecutor" ref="asyncExecutor" />
<property name="asyncExecutorEnabled" value="true" />
<property name="asyncExecutorActivate" value="true" />

<bean id="asyncExecutor" class="org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor">
    <property name="corePoolSize" value="20" />
    <property name="maxPoolSize" value="50" />
    <property name="keepAliveTime" value="3000" />
    <property name="queueSize" value="200" />
    <property name="maxTimerJobsPerAcquisition" value="2" />
    <property name="maxAsyncJobsDuePerAcquisition" value="2" />
    <property name="defaultAsyncJobAcquireWaitTimeInMillis" value="1000" />
    <property name="defaultTimerJobAcquireWaitTimeInMillis" value="1000" />
    <property name="timerLockTimeInMillis" value="60000" />
    <property name="asyncJobLockTimeInMillis" value="60000" />
</bean>

The problem is that i get ActivitiOptimisticLockingException and NullPointerException when applications try to run processes cause bouth of apps may try to run the same job. Apps work normal if not pay attention to exceptions, but i I would like to know is there any hint how to run several apps with async processes on same DB, and may be there is a way to make apps to run only own jobs?

Upvotes: 1

Views: 1555

Answers (1)

Greg Harley
Greg Harley

Reputation: 3240

The first thing you need to do is enable Strong UUID's. This is enabled by adding the following into your Activiti configuration class:

StrongUuidGenerator idGenerator = new StrongUuidGenerator(); processEngineConfiguration.setIdGenerator(idGenerator);

Why do I believe this will help? Because it is likely the Optimistic lock you are experiencing is from retrieving the next ID from the database. The Strong UUID generator doesnt touch the database and as such is better suited to large scale apps.

Hope this helps.

Upvotes: 1

Related Questions