I want to propose a feature where you can tell the @Async annotation to put a Job at the end of the executor queue.

Why?

Imagine you have a lot of database updates and the database uses lock by page, when you have thousands of jobs that take a while and are run asynchronusly one might go on the same page as the other and you get a PessimisticLock-Exception or an JpaSystemFailureException.

Example

In those cases it would be great if we could implement something like this:

@Async(retryMode=AsyncRetryMode.END_OF_QUEUE, retry=@Retryable(retryFor={PessimsitcLockException.class, JpaSystemException.class}, maxAttempts=10, backoff=@Backoff(delay=2_500, maxDelay=60_000, multiplier = 1.5, random = true)))

This would mean if the job fails with a PessimistcLockException: 1. Wait the delay 2. Put the job at the end of the queue 3. After max attempts throw the Exception and try to get into @Recover

Comment From: sdeleuze

Hi, this issue seems to describe a pretty advanced feature more than just a refinement of @Async. I can see how it could be useful for some use cases but it looks like too opinionated and too linked to https://github.com/spring-projects/spring-retry concepts to be implemented at Spring Framework level in a reasonable time frame in a reasonable way. As a consequence, I will decline it.