Boost Your Java Services with Fast‑Retry: High‑Performance Asynchronous Retry Framework
Fast‑Retry is a high‑performance multi‑task asynchronous retry framework for Java that outperforms traditional synchronous retry libraries like Spring‑Retry and Guava‑Retry, offering flexible APIs, annotation support, and dramatic throughput gains for massive retry scenarios.
Introduction
When a system has millions of users and needs to poll and retry fetching each user's identity, traditional single‑task synchronous retry frameworks such as Spring‑Retry or Guava‑Retry become impractical. Fast‑Retry is designed for this scenario.
What is Fast‑Retry?
Fast‑Retry is a high‑performance multi‑task retry framework that supports asynchronous retry for millions of tasks, offering both programmatic and annotation‑based usage and customizable result‑retry logic.
Comparison with Spring‑Retry and Guava‑Retry
Unlike the synchronous single‑task frameworks, Fast‑Retry performs asynchronous retries, avoiding thread‑pool exhaustion and delivering exponential performance gains. A benchmark shows Fast‑Retry handling 1 000 000 tasks faster than Spring‑Retry and Guava‑Retry can handle 50 tasks.
Test thread pool: 8 fixed threads
Single task logic: poll 5 times, 2 s interval, total 10 s
Estimated formula: total time ≈ (task count / concurrency) × single‑task retry time
Quick Start
Dependency
<dependency>
<groupId>io.github.burukeyou</groupId>
<artifactId>fast-retry-all</artifactId>
<version>0.2.0</version>
</dependency>Constructing Retry Tasks
Three approaches are provided:
Use a RetryQueue directly to define a RetryTask with custom retry interval, retry condition, and result retrieval.
Use FastRetryBuilder to simplify task creation.
Use the @FastRetry annotation for declarative retry, integrated with Spring.
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()); FastRetryBuilder.<String>builder()
.attemptMaxTimes(3)
.waitRetryTime(3, TimeUnit.SECONDS)
.retryIfException(true)
.retryIfExceptionOfType(TimeoutException.class)
.exceptionRecover(true)
.resultPolicy(result -> result.equals("444"))
.build()
.submit(() -> {
if (0 < 10) { throw new TimeoutException("test"); }
return "444";
}); @FastRetry(retryWait = @RetryWait(delay = 2))
public String retryTask() {
return "success";
}Custom Retry Annotation
You can define your own annotation based on @FastRetry and implement AnnotationRetryTaskFactory, with the default implementation being FastRetryAnnotationRetryTaskFactory.
Recommendations
Prefer asynchronous retry returning CompletableFuture and handle the result with whenComplete.
Resources
GitHub project: https://github.com/burukeYou/fast-retry
Maven repository: 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.
