Backend Development 7 min read

Fast‑Retry: High‑Performance Asynchronous Retry Framework for Java

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 easy integration for massive retry workloads.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Fast‑Retry: High‑Performance Asynchronous Retry Framework for Java

When dealing with massive retry workloads—such as polling identity information for one million users—traditional synchronous retry libraries (Spring‑Retry, Guava‑Retry) become a bottleneck, even with many threads. Fast‑Retry is designed for this scenario, providing an asynchronous, high‑throughput retry engine.

Fast‑Retry differs from mainstream single‑task synchronous frameworks by supporting asynchronous retries, timeout handling, and callbacks. Benchmarks show that even with 1 000 000 tasks, Fast‑Retry’s throughput surpasses Spring‑Retry and Guava‑Retry handling only 50 tasks, thanks to its non‑blocking design.

Quick start

Add the Maven dependency:

<dependency>
    <groupId>io.github.burukeyou</groupId>
    <artifactId>fast-retry-all</artifactId>
    <version>0.2.0</version>
</dependency>

There are three main ways to build a retry task:

Use a RetryQueue directly, which works like a thread‑pool API.

Use FastRetryBuilder to simplify RetryTask creation.

Use the @FastRetry annotation for declarative retry logic.

Example with RetryQueue

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());

Example with FastRetryBuilder

RetryResultPolicy
resultPolicy = result -> result.equals("444");
FastRetryer
retryer = FastRetryBuilder.<String>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);

Example with @FastRetry annotation

@FastRetry(retryWait = @RetryWait(delay = 2))
public String retryTask() {
    return "success";
}

For asynchronous usage, return a CompletableFuture and handle the result with whenComplete :

@FastRetry(retryWait = @RetryWait(delay = 2))
public CompletableFuture
retryTask() {
    return CompletableFuture.completedFuture("success");
}

You can also define custom retry annotations by implementing AnnotationRetryTaskFactory ; the default implementation is FastRetryAnnotationRetryTaskFactory .

Usage recommendations

Prefer asynchronous retry methods that return CompletableFuture and use whenComplete to process the result, ensuring non‑blocking execution.

Other resources

GitHub repository: https://github.com/burukeYou/fast-retry

Maven Central: https://central.sonatype.com/artifact/io.github.burukeyou/fast-retry-all

backendJavaperformanceasynchronousretryFast-Retry
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.