Class RetrySynchronizationManager
java.lang.Object
org.springframework.retry.support.RetrySynchronizationManager
Global variable support for retry clients. Normally it is not necessary for clients to
be aware of the surrounding environment because a
RetryCallback can always use
the context it is passed by the enclosing RetryOperations. But occasionally it
might be helpful to have lower level access to the ongoing RetryContext so we
provide a global accessor here. The mutator methods (clear() and
register(RetryContext) should not be used except internally by
RetryOperations implementations.- Author:
- Dave Syer, Gary Russell
-
Method Summary
Modifier and TypeMethodDescriptionstatic RetryContextclear()Clear the current context at the end of a batch - should only be used byRetryOperationsimplementations.static RetryContextPublic accessor for the locally enclosingRetryContext.static booleanReturn true if contexts are held in a ThreadLocal (default) rather than a Map.static RetryContextregister(RetryContext context) Method for registering a context - should only be used byRetryOperationsimplementations to ensure thatgetContext()always returns the correct value.static voidsetUseThreadLocal(boolean use) Set to false to store the context in a map (keyed by the current thread) instead of in aThreadLocal.
-
Method Details
-
setUseThreadLocal
public static void setUseThreadLocal(boolean use) Set to false to store the context in a map (keyed by the current thread) instead of in aThreadLocal. Recommended when using virtual threads.- Parameters:
use- true to use aThreadLocal(default true).- Since:
- 2.0.3
-
isUseThreadLocal
public static boolean isUseThreadLocal()Return true if contexts are held in a ThreadLocal (default) rather than a Map.- Returns:
- the useThreadLocal
- Since:
- 2.0.3
-
getContext
Public accessor for the locally enclosingRetryContext.- Returns:
- the current retry context, or null if there isn't one
-
register
Method for registering a context - should only be used byRetryOperationsimplementations to ensure thatgetContext()always returns the correct value.- Parameters:
context- the new context to register- Returns:
- the old context if there was one
-
clear
Clear the current context at the end of a batch - should only be used byRetryOperationsimplementations.- Returns:
- the old value if there was one.
-