Spring DeadLocks retries
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 14 Oct 2014 17:21:46 +0000 (19:21 +0200)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Tue, 14 Oct 2014 17:21:46 +0000 (19:21 +0200)
SpringJava/DeadLocksSQL/src/main/java/de/example/sql/deadlocks/aspect/DeadlockRetryAspect.java
SpringJava/DeadLocksSQL/src/main/resources/spring-config.xml

index 6d1006f..1aa1915 100644 (file)
@@ -72,7 +72,10 @@ public class DeadlockRetryAspect implements Ordered {
                }
        } while (count < maxTries);
 
-       throw new RuntimeException("DeadlockRetry failed, deadlock in all retry attempts.", lastException);
+       // Throwing exception because it matched or it contains (exception chaining)
+       // some of the exceptions from the list in the spring-config.xml file.
+       // The exception being thrown will depend on the API that you are using.
+       throw lastException;
     }
 
        @Override
index f8c6235..ff5e273 100644 (file)
 
     <bean id="deadlockRetryAspect" class="de.example.sql.deadlocks.aspect.DeadlockRetryAspect">
                <property name="retryableExceptionClasses">
+                   <!--
+                     You have to add here the exceptions for your API. In this case it is
+                     spring-tx and JDBC.
+                    -->
                        <list value-type="java.lang.String">
                                <value>com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException</value>
+                               <value>org.springframework.dao.DeadlockLoserDataAccessException</value>
                        </list>
                </property>
     </bean>