Does spring @Retryable create a new connection or use the same c

ghz 8months ago ⋅ 70 views

Does spring @Retryable create a new connection or use the same connection with server

I have a Spring project wherein I am using @Retryable annotation on a method. The method calls an API and posts some json payload to it.

I have set maxAttempts as 4 and a retry delay of 20 ms using Backoff.

I am debugging an issue and hence trying to understand if @Retryable creates a new connection(a new thread) with the server where the API is hosted after the specified delay(20 ms in my case) or uses the same connection(same thread)

Answers

The @Retryable annotation in Spring Retry does not create a new connection or thread with the server when retrying a method call. Instead, it retries the method call within the same thread that initiated the original method invocation.

When the method annotated with @Retryable encounters an exception, Spring Retry will catch the exception and attempt to retry the method call based on the configured retry settings (such as maxAttempts and backoff). During the retry attempts, the method will be re-invoked within the same thread context.

The backoff strategy determines the delay between retry attempts. In your case, you've configured a backoff with a delay of 20 milliseconds. After each failed attempt, Spring Retry will wait for the specified delay before retrying the method call again. This delay occurs within the same thread that executed the original method call.

So, to answer your question, @Retryable does not create new connections or threads with the server during retry attempts. It retries the method call within the same thread context, applying the specified delay between retry attempts.