spring @Retryable 是创建新连接还是与服务器使用相同的连接

问题描述 投票:0回答:1

我有一个 Spring 项目,其中我在方法上使用 @Retryable 注释。该方法调用 API 并向其发送一些 json 有效负载。

我已使用

maxAttempts
Backoff
设置为 4 并重试延迟 20 毫秒。

我正在调试一个问题,因此试图了解 @Retryable 是否在指定的延迟(在我的情况下为 20 毫秒)后与托管 API 的服务器创建新连接(新线程)或使用相同的连接(相同的线程) )

spring multithreading threadpool spring-retry
1个回答
0
投票

@Retryable
使用
RetryTemplate
并且其逻辑如下:

        while (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) {

            try {
                ...
                T result = retryCallback.doWithRetry(context);
                doOnSuccessInterceptors(retryCallback, context, result);
                return result;
            }
            catch (Throwable e) {

                ...

                if (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) {
                    ...
                }

                ...
        }

因此,所有重试尝试都发生在同一线程上——调用线程。

© www.soinside.com 2019 - 2024. All rights reserved.