記錄一下吧。
今天將生產環境的幾個服務節點改成集群模式,其中包含activiti審批服務節點,其中各個服務幾點間數據通信采用MQ(與本文無關)。
然后報出如題錯誤。
究其原因就是,在啟動activiti自動審批工作流的時候,activiti會查詢act_ge_property表中的值來標識唯一工作流。單機情況下不會出現此狀況,集群情況下才會出現該表鎖異常的情況,所以報出了此錯誤。
解決方法,就是在activiti配置文件中不讓activiti在啟動工作流的時候查詢這張表,即采用主鍵注入策略,具體實行方法非常簡單。
1、需在項目中引入java-uuid-generator-3.1.2.jar包。有了此包才能生成UUID。
2、在activiti配置文件中加入
<property name="idGenerator"><bean class="org.activiti.engine.impl.persistence.StrongUuidGenerator" /></property>
至於為什么要引入這個包,是因為:
package org.activiti.engine.impl.persistence; import org.activiti.engine.impl.cfg.IdGenerator; import com.fasterxml.uuid.EthernetAddress; import com.fasterxml.uuid.Generators; import com.fasterxml.uuid.impl.TimeBasedGenerator; /** * {@link IdGenerator} implementation based on the current time and the ethernet * address of the machine it is running on. * * @author Daniel Meyer */ public class StrongUuidGenerator implements IdGenerator { // different ProcessEngines on the same classloader share one generator. protected static TimeBasedGenerator timeBasedGenerator; public StrongUuidGenerator() { ensureGeneratorInitialized(); } protected void ensureGeneratorInitialized() { if (timeBasedGenerator == null) { synchronized (StrongUuidGenerator.class) { if (timeBasedGenerator == null) { timeBasedGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface()); } } } } public String getNextId() { return timeBasedGenerator.generate().toString(); } }
就OK了。
這樣就可以采用主鍵注入策略,而不使用activiti表中的值。也就不會再報出這個錯誤。
參考文章鏈接地址:http://blog.csdn.net/kongqz/article/details/8027295