A simple task retry scheduler to demonstrate the first principles of a robust retry system. Built using Java concurrency primitives.
This project simulates a retry mechanism that retries failed tasks using thread-safe queues and a scheduled retry loop (in a production-grade retry system, a persistent retry queue is preferred to an in-memory queue).
This project demonstrates the first principles of implementing a retry system in core Java using:
BlockingQueueto buffer failed tasksScheduledExecutorServicea dedicated thread to periodically poll the queueExecutorServiceto retry tasks using worker threads- A shutdown hook: a dedicated thread that gracefully terminates the threads
- Retry logic that adds persistently failing tasks to a Dead letter Queue after 3 failed attempts.
- Exponential Backoff to avoid overloading the retry system
Each task has a retry count and is either:
- Re-queued on failure (up to 3 times)
- Redirected to a Dead Letter Queue (DLQ) after max retries
| Tool | Description |
|---|---|
| Java 21+ | Language for core logic |
| Maven | Build automation and dependency management |
java.util.logging |
Logging (default is java.util.logging) |
β No third-party libraries required β pure Java!
- Tasks are simulated via
doTask(task). - These are placed into a
LinkedBlockingQueue. - A scheduled task polls this queue every 10 seconds.
- If a task is present, it's submitted to a thread pool for execution.
- If the task fails, it's retried up to 3 times.
- After 3 failed retries, the task is logged as permanently failed.
- Java 21 or higher
- Maven 3.x
mvn clean installYou can run the main class using maven (if you have maven installed):
mvn exec:java -Dexec.mainClass="org.emjay.task_retry.RetryApplication"Or run using your IDE run configuration