Getting “Deadlock found when trying to get lock; try restarting transaction”

后端 未结 5 1761
一个人的身影
一个人的身影 2020-12-07 21:11

My Application(java spring-core) has several threads running concurrently and accessing db, I am getting exception in some peaktime

07:43:33,400 WARN  [org.         


        
5条回答
  •  一个人的身影
    2020-12-07 21:37

    Emir's answer is great and it describes the problem that you are getting. However I suggest you to try spring-retry.

    It's a brilliant framework that implements the retry pattern via annotation(s).

    Example:

     @Retryable(maxAttempts = 4, backoff = @Backoff(delay = 500))
     public void doSomethingWithMysql() {
       consumerTransactionTemplate.execute(
                 new TransactionCallbackWithoutResult(){
                    @Override
                    protected void doInTransactionWithoutResult(                 
                          TransactionStatus status)
                    {
                        process();
                    }
    
                });
     } 
    

    In case of exception, it will retry (call) up to 4 times the method doSomethingWithMysql() with a backoff policy of 500ms

提交回复
热议问题