Why Fast‑Retry Beats Spring‑Retry for Million‑Task Scenarios
The article explains how Fast‑Retry, an asynchronous multi‑task retry framework, dramatically outperforms synchronous retry libraries like Spring‑Retry and Guava‑Retry when handling massive workloads, and provides step‑by‑step code examples, performance benchmarks, and integration tips for Java developers.
Problem
When a system must retrieve identity information for one million users, single‑task synchronous retry libraries such as Spring‑Retry or Guava‑Retry become infeasible. Even with many machines and threads the processing time grows linearly and quickly exhausts thread resources.
Fast‑Retry Overview
Fast‑Retry is a high‑performance asynchronous retry framework that supports millions of concurrent retry tasks. It provides both programmatic and annotation‑based APIs and allows custom result‑based retry logic.
Performance Comparison
The benchmark uses an 8‑thread fixed pool. Each task polls five times with a 2‑second interval, so a single task takes 10 seconds. The estimated total processing time follows tasks / concurrency × singleTaskTime. Results show that Fast‑Retry processes one million tasks faster than Spring‑Retry or Guava‑Retry can handle just 50 tasks, demonstrating an exponential throughput advantage.
Getting Started
Dependency
<dependency>
<groupId>io.github.burukeyou</groupId>
<artifactId>fast-retry-all</artifactId>
<version>0.2.0</version>
</dependency>Construction Methods
1. Using a RetryQueue
ExecutorService executorService = Executors.newFixedThreadPool(8);
RetryQueue queue = new FastRetryQueue(executorService);
RetryTask<String> task = new RetryTask<String>() {
int result = 0;
@Override public long waitRetryTime() { return 2000; }
@Override public boolean retry() { return ++result < 5; }
@Override public String getResult() { return result + ""; }
};
CompletableFuture<String> future = queue.submit(task);
log.info("Task finished, result:{}", future.get());2. Using FastRetryBuilder
RetryResultPolicy<String> resultPolicy = result -> result.equals("444");
FastRetryer<String> retryer = FastRetryBuilder<String>builder()
.attemptMaxTimes(3)
.waitRetryTime(3, TimeUnit.SECONDS)
.retryIfException(true)
.retryIfExceptionOfType(TimeoutException.class)
.exceptionRecover(true)
.resultPolicy(resultPolicy)
.build();
CompletableFuture<String> future = retryer.submit(() -> {
log.info("retry");
if (0 < 10) {
throw new TimeoutException("test");
}
return "444";
});
String o = future.get();
log.info("Result {}", o);3. Using @FastRetry Annotation
@FastRetry(retryWait = @RetryWait(delay = 2))
public String retryTask(){
return "success";
}
@FastRetry(retryWait = @RetryWait(delay = 2))
public CompletableFuture<String> retryTask(){
return CompletableFuture.completedFuture("success");
}Custom Annotation
If the built‑in annotation does not fit, developers can define their own annotation, mark it with @FastRetry, specify a custom factory, and implement AnnotationRetryTaskFactory. The default implementation is FastRetryAnnotationRetryTaskFactory.
Best Practices
Prefer asynchronous retry (methods returning CompletableFuture) and handle the final result with whenComplete.
References
GitHub project: https://github.com/burukeYou/fast-retry (fast-retry-demo module contains usage examples)
Maven Central: https://central.sonatype.com/artifact/io.github.burukeyou/fast-retry-all
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect
Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
