項目使用的工作流引擎是Activiti 5.12,數據庫是MySQL
背景:
前段時間項目掛到測試服務器上進行測試了,
結果後來每天早上項目重新打包後的第一次工作流提交操作,都會發生錯誤。
在項目的日誌文件裏面找到類似的這個錯誤:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 31,303,700 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectProperty-Inline
### The error occurred while setting parameters
### SQL: select * from ACT_GE_PROPERTY where NAME_ = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 31,303,700 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago.
已wait_timeout爲關鍵字搜索,經過分析得到結論:
是由於Mysql服務器的wait_timeout 屬性造成的,Mysql默認的“wait_timeout”是8小時(28800 second),也就是說一個connection空閒超過8個小時,Mysql將自動斷開該connection,但是在項目中的數據庫連接現在是不知道這個連接是已經失效的,如果這時有客戶端請求connection,並執行相應操作,將會造成上面的異常。
類似錯誤:http://forums.activiti.org/content/mysql-exception
不過好的是,在Activiti中可以使用連接池:
官網文檔:http://activiti.org/userguide/index.html#databaseConfiguration
然後配置上相應的數據庫連接屬性,應該就好了。
不過具體的還有待我驗證兩天,如有問題,還望指出!