【问题标题】:Async service tasks on clustered applications with Activiti engine使用 Activiti 引擎在集群应用程序上执行异步服务任务
【发布时间】:2015-07-28 23:21:32
【问题描述】:

我有 2 个应用程序在同一个数据库上运行。 他们都像这样启动activiti进程:

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 导致两个应用程序可能尝试运行相同的作业。如果不注意异常,应用程序可以正常工作,但我想知道是否有任何提示如何在同一个数据库上运行具有异步进程的多个应用程序,并且可能有办法让应用程序只运行自己的作业?

【问题讨论】:

    标签: java activiti bpmn


    【解决方案1】:

    您需要做的第一件事是启用强 UUID。这可以通过将以下内容添加到您的 Activiti 配置类中来启用:

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

    为什么我相信这会有所帮助?因为您遇到的乐观锁很可能来自从数据库中检索下一个 ID。 Strong UUID 生成器不涉及数据库,因此更适合大型应用程序。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-23
      • 2021-10-18
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      相关资源
      最近更新 更多