public final class ThreadLocalHelper extends Object
ThreadLocal.
This class provides helper methods for fetching values from ThreadLocal,
taking care of initializing the value if not present.
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
getSTL(@NotNull ThreadLocal<T> threadLocal,
@NotNull Supplier<T> supplier)
Retrieves a thread-local value, or creates a new one using a supplier if none exists.
|
static <T,A> T |
getTL(@NotNull ThreadLocal<WeakReference<T>> threadLocal,
A a,
@NotNull Function<A,T> function)
Retrieves a thread-local weakly-referenced value, or creates a new one using a function if none exists.
|
static <T,A> T |
getTL(@NotNull ThreadLocal<WeakReference<T>> threadLocal,
A supplyingEntity,
@NotNull Function<A,T> constructor,
@Nullable ReferenceQueue<T> referenceQueue,
@Nullable Consumer<WeakReference<T>> registrar)
Retrieves a thread-local weakly-referenced value, or creates a new one using a function if none exists.
|
static <T> T |
getTL(@NotNull ThreadLocal<WeakReference<T>> threadLocal,
@NotNull Supplier<T> supplier)
Retrieves a thread-local weakly-referenced value, or creates a new one using a supplier if none exists.
|
@NotNull
public static <T> T getTL(@NotNull
@NotNull ThreadLocal<WeakReference<T>> threadLocal,
@NotNull
@NotNull Supplier<T> supplier)
T - The type of the value.threadLocal - The ThreadLocal object to retrieve or create a value for.supplier - The supplier to generate a new value if necessary.@NotNull
public static <T> T getSTL(@NotNull
@NotNull ThreadLocal<T> threadLocal,
@NotNull
@NotNull Supplier<T> supplier)
T - The type of the value.threadLocal - The ThreadLocal object to retrieve or create a value for.supplier - The supplier to generate a new value if necessary.@NotNull
public static <T,A> T getTL(@NotNull
@NotNull ThreadLocal<WeakReference<T>> threadLocal,
A a,
@NotNull
@NotNull Function<A,T> function)
T - The type of the value.A - The type of the input to the function.threadLocal - The ThreadLocal object to retrieve or create a value for.a - The input for the function to generate a new value if necessary.function - The function to generate a new value if necessary.@NotNull
public static <T,A> T getTL(@NotNull
@NotNull ThreadLocal<WeakReference<T>> threadLocal,
@NotNull
A supplyingEntity,
@NotNull
@NotNull Function<A,T> constructor,
@Nullable
@Nullable ReferenceQueue<T> referenceQueue,
@Nullable
@Nullable Consumer<WeakReference<T>> registrar)
T - The type of the value.A - The type of the input to the function.threadLocal - The ThreadLocal object to retrieve or create a value for.supplyingEntity - The input for the function to generate a new value if necessary.constructor - The function to generate a new value if necessary.referenceQueue - The reference queue to register the weak reference in.registrar - The consumer to use for registration of the weak reference.Copyright © 2024. All rights reserved.