Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
use aspectj to retry deadlocked transactions in spring boot

I created a deadlock situation by having 2 functions lock 2 rows in a mysql table in opposite orders. I have @Transactional on both functions. I also have an aspectj aspect on both functions that retries the failed one at most 2 more times.

After the deadlock, one thread succeeds and one fails. The failed one retries. So far so good. However, there are 2 problems after this point.

  1. When the failed function was retried a second time, it reads the 2 rows again. However, the value for the first one is old and the second one is new.

  2. At the end, the transaction fails because the transaction was already marked for rollback. So the @Transactional proxy is around the retry proxy. Is there a way to reverse the order? I tried to have the retry proxy inherit Ordered and set the order to Ordered.HIGHEST_VALUE and Ordered.LOWEST_VALUE but neither worked.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I tried spring retry and it worked like a charm. Still looking into how it does it magic though.

I basically did this:

add dependency on org.springframework.retry spring-retry

add @EnableRetry to application

add @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000)) above @Transactional annotated functions.

about 4 years ago · Santiago Trujillo Report

0

This one has the more direct answer:

Intercepting @Transactional After Optimistic Lock for Asynchronous Calls in Restful App

Just added @Order(1) below the aspect.

Turned out the key was to use 1 as the order. I tried the Ordered interface again just like in the problem description. This time using 1 and it worked just the same as the Order annotation is just a shortcut to the interface.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!