flowable 6.4.1 FlowableOptimisticLockingException

flowable FlowableOptimisticLockingException

最近使用flowable開發時,由於業務代碼使用了 @Transactional 導致保存業務變量時出錯,提示如問題描述

問題描述

xxx was updated by another transaction concurrently
2019-11-19 09:40:11.671 ERROR[ad-196]c.z.o.f.s.impl.ApplyServiceImpl.approvePass<2003> approvePass Execption :{}
org.flowable.common.engine.api.FlowableOptimisticLockingException: Task[id=316750988787904512, name=流程管理員] was updated by another transaction concurrently
at org.flowable.common.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:505)
at org.flowable.common.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:292)
at org.flowable.common.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:191)
at org.flowable.common.engine.impl.interceptor.CommandContext.close(CommandContext.java:61)
at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:80)

問題分析

由於flowable處理併發時,是屬於僞併發,採用樂觀鎖機制處理。在由同一數據條目的併發訪問引起的數據存儲中發生樂觀鎖定時拋出。

源代碼分析

在這裏插入圖片描述

解決方案

根據實際需要設置事務隔離和傳播

@Transactional(rollbackFor = {RuntimeException.class, Exception.class}, propagation = Propagation.NESTED,isolation = Isolation.READ_UNCOMMITTED)
propagation 屬性

事務的傳播行爲,默認值爲 Propagation.REQUIRED。

可選的值有:

Propagation.REQUIRED

如果當前存在事務,則加入該事務,如果當前不存在事務,則創建一個新的事務。

Propagation.SUPPORTS

如果當前存在事務,則加入該事務;如果當前不存在事務,則以非事務的方式繼續運行。

Propagation.MANDATORY

如果當前存在事務,則加入該事務;如果當前不存在事務,則拋出異常。

Propagation.REQUIRES_NEW

重新創建一個新的事務,如果當前存在事務,暫停當前的事務。

Propagation.NOT_SUPPORTED

以非事務的方式運行,如果當前存在事務,暫停當前的事務。

Propagation.NEVER

以非事務的方式運行,如果當前存在事務,則拋出異常。

Propagation.NESTED

和 Propagation.REQUIRED 效果一樣。

isolation 屬性
事務的隔離級別,默認值爲 Isolation.DEFAULT。

可選的值有:

Isolation.DEFAULT

使用底層數據庫默認的隔離級別。

Isolation.READ_UNCOMMITTED

Isolation.READ_COMMITTED
Isolation.REPEATABLE_READ
Isolation.SERIALIZABLE

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章