I need to call an url and it's possible that call return bad http code like 404, 500 etc. I want to implement a retry feature when I get those errors: a new call will be proceed every hour and ten times maximum.
I use the async-http-client library to do my POST call async.
Do you have any idea?
Thanks in advance for your help.
It's worth considering the Spring Retry functionality.
The API is constructed to be agnostic to what you want to retry, and concerns itself with retry policies, backoffs, limiting number of retries etc.
Another possibility if you're using Java 7/8 is the AsyncRetryExecutor. e.g.
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
RetryExecutor executor = new AsyncRetryExecutor(scheduler).
retryOn(SocketException.class).
withExponentialBackoff(500, 2). //500ms times 2 after each retry
withMaxDelay(10_000). //10 seconds
withUniformJitter(). //add between +/- 100 ms randomly
withMaxRetries(20);