Fast‑Retry: High‑Performance Asynchronous Multi‑Task Retry Framework for Java
Fast‑Retry is a high‑performance Java library that enables asynchronous, multi‑task retry with customizable logic, offering a scalable alternative to synchronous retry frameworks like Spring‑Retry and Guava‑Retry for handling massive workloads such as millions of user identity queries.
Preface
When a system needs to poll and retry identity information for millions of users, traditional synchronous retry frameworks such as Spring‑Retry or Guava‑Retry become impractical, even with abundant threads; Fast‑Retry was created to solve this problem.
Fast‑Retry Overview
Fast‑Retry is a high‑performance, multi‑task retry framework that supports millions of asynchronous retry tasks and offers both programmatic and annotation‑based usage, as well as custom result‑based retry logic.
What Is This?
Unlike mainstream single‑task synchronous retry frameworks, Fast‑Retry provides asynchronous retry, timeout waiting, and callbacks, allowing massive parallel retries without exhausting thread resources.
Performance tests with an 8‑thread pool and a task that retries five times with a 2‑second interval show that Fast‑Retry outperforms Spring‑Retry and Guava‑Retry even when they handle only 50 tasks, demonstrating exponential throughput gains.
Quick Start
Add Dependency
<dependency>
<groupId>io.github.burukeyou</groupId>
<artifactId>fast-retry-all</artifactId>
<version>0.2.0</version>
</dependency>There are three ways to build a retry task.
Using RetryQueue
RetryTask lets you configure retry logic such as intervals, conditions, and result handling. For simple cases, prefer FastRetryBuilder or the @FastRetry annotation.
RetryQueue is the core executor, similar to a thread‑pool API.
ExecutorService executorService = Executors.newFixedThreadPool(8);
RetryQueue queue = new FastRetryQueue(executorService);
RetryTask
task = new RetryTask
() {
int result = 0;
@Override
public long waitRetryTime() { return 2000; }
@Override
public boolean retry() { return ++result < 5; }
@Override
public String getResult() { return result + ""; }
};
CompletableFuture
future = queue.submit(task);
log.info("任务结束 结果:{}", future.get());Using FastRetryBuilder
The builder internally uses RetryQueue but simplifies the construction of RetryTask .
RetryResultPolicy
resultPolicy = result -> result.equals("444");
FastRetryer
retryer = FastRetryBuilder.
builder()
.attemptMaxTimes(3)
.waitRetryTime(3, TimeUnit.SECONDS)
.retryIfException(true)
.retryIfExceptionOfType(TimeoutException.class)
.exceptionRecover(true)
.resultPolicy(resultPolicy)
.build();
CompletableFuture
future = retryer.submit(() -> {
log.info("重试");
if (0 < 10) {
throw new TimeoutException("test");
}
return "444";
});
String o = future.get();
log.info("结果{}", o);Using @FastRetry Annotation
The annotation also relies on RetryQueue and integrates with Spring; enable it with @EnableFastRetry .
@FastRetry(retryWait = @RetryWait(delay = 2))
public String retryTask() {
return "success";
}When the method returns a CompletableFuture , the framework automatically handles asynchronous polling.
@FastRetry(retryWait = @RetryWait(delay = 2))
public CompletableFuture
retryTask() {
return CompletableFuture.completedFuture("success");
}Custom Retry Annotation
You can define your own annotation, mark it with @FastRetry , and implement AnnotationRetryTaskFactory to provide custom task construction logic; the default implementation is FastRetryAnnotationRetryTaskFactory .
Usage Recommendations
Regardless of the construction method, prefer asynchronous retry returning CompletableFuture and use its whenComplete method to handle results.
Other
GitHub project : https://github.com/burukeYou/fast-retry
Maven repository : https://central.sonatype.com/artifact/io.github.burukeyou/fast-retry-all
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
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.