Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

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.

over 4 years ago · Santiago Trujillo Relatório

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda