2011-07-11 100 views
3

如何重新啓動交易(這樣至少執行一次),當我們得到:如何在Java中死鎖或超時後重新啓動事務?

(com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException:試圖獲取鎖定時發現死鎖;嘗試重新啓動交易)或(交易超時)?

我正在使用MySQL(innoDB ENGINE)和Java.Please幫助並鏈接任何有用的資源或代碼。

回答

1

當你永遠在你的catch塊捕獲這種類型的異常

catch(Exception e){ 
if(e instanceof TransactionRollbackException){ 
//Retrigger Your Transaction 
    } 
// log your exception or throw it its upto ur implementation 
} 
+0

你確定這是特定於死鎖嗎?我不希望陷入無限循環除了死鎖之外,可以拋出'TransactionRollbackException'。 – xLite

1

如果您使用純JDBC,你必須做手工,在一個循環(不要忘記檢查的先決條件的每一次。
如果您使用的春天「 How to restart transactions on deadlock/lock-timeout in Spring?」高度重視和幫助。

+0

您好,感謝使用純JDBC您response.I'm。能否請您給像一個示例代碼(){}交易爲檢查前提條件 – ravi

相關問題