开发者

How to restart transaction after deadlocked or timed out in Java ?

开发者 https://www.devze.com 2023-03-19 02:31 出处:网络
How to restart a transaction (so that it executes at least once) when we get: ( com.mysql.jdbc.exceptions.开发者_如何转开发jdbc4.MySQLTransactionRollbackException:Deadlock found when trying to get l

How to restart a transaction (so that it executes at least once) when we get:

( com.mysql.jdbc.exceptions.开发者_如何转开发jdbc4.MySQLTransactionRollbackException:Deadlock found when trying to get lock; Try restarting transaction ) OR ( transaction times out ) ?

I'm using MySQL(innoDB ENGINE) and Java.Please help and also link any useful resources or codes.


When ever you are catching such type of exception in your catch block

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


If you use plain JDBC, you have to do it manually, in a loop (and don't forget to check the pre-conditions every time.
If you use spring, "How to restart transactions on deadlock/lock-timeout in Spring?" sould help.

0

精彩评论

暂无评论...
验证码 换一张
取 消