0

I want to have a retry mechanism where if a task is failed and it should be retried after an interval without blocking or sleeping any thread.

For example, lets assume I have maxRetryAttempt as 3 and interval between retry is 3 seconds. I have list of task 1,2, 3,..10 Worker thread picks the task 1. If Task 1 is failed now and I want to retry it but next retry attempt is after 3 seconds. Here I dont want to put my thread into sleep. Instead of that, I want to put the task into some queue and worker thread should pick the task exactly after 3 seconds to retry that task.

I have checked few existing libraries like spring-retry. Those are libraries taking a job and making a thread to sleep before another attempt. So that all tasks are taking 9 seconds before give up (assume worst case, all tasks are failing due to some problem). In this case, 10 different worker threads are getting populated and all are waiting.

Is there any library or design pattern or idea which is matching my expectation?

Raashith
  • 155
  • 3
  • 16
  • Sounds like you want to use some kind of a `Timer` or `Scheduler`. Different frameworks provide different variations on the idea. I don't know what it looks like in spring-boot, but maybe you can find a clue here: https://spring.io/guides/gs/scheduling-tasks/ – Solomon Slow Jul 01 '20 at 14:11

1 Answers1

0

You probably want to check out the RxJava library: http://reactivex.io/

It has an operator for asynchronous operations that does exactly what you want it to do: retryWhen

KUSH42
  • 552
  • 2
  • 13