我有2个应用程序在同一个数据库上运行。
他们两个都开始这样的激活过程:
for (i = 0; i < msgNbr; i++) {
Map<String, Object> dataMap = Data.prepareData(testOptions);
runtimeService.startProcessInstanceByKey("asyncTransferProcess", dataMap);
}
正在启动的进程中的第一个服务任务是异步的:
<serviceTask id="serviceTask1" name="ServiceTask1" activiti:exclusive="true"
activiti:class="com.test.activiti.async.ServiceTask1"></serviceTask>
异步执行程序配置:
<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>
问题是,当应用程序尝试运行进程时,我得到了ActivitiOptimisticLockingException和NullPointerException,这是因为应用程序的运行可能会尝试运行同一作业。如果不注意例外,应用程序就会正常工作,但是我想知道是否有任何提示如何在同一个数据库上运行带有异步进程的多个应用程序,并且也许有一种方法可以使应用程序仅运行自己的作业?
最佳答案
您需要做的第一件事是启用强UUID。通过将以下内容添加到Activiti配置类中,可以启用此功能:
StrongUuidGenerator idGenerator =新的StrongUuidGenerator();
processEngineConfiguration.setIdGenerator(idGenerator);
为什么我相信这会有所帮助?因为您遇到的乐观锁很可能是从数据库中检索下一个ID。 Strong UUID生成器不会接触数据库,因此更适合于大型应用程序。
希望这可以帮助。