public class CleaningThreadLocal<T> extends ThreadLocal<T>
Note: this will not clean up the resource if the ThreadLocal itself is discarded.
Modifier and Type | Method and Description |
---|---|
void |
cleanup(T value)
Cleanup.
|
T |
get() |
protected T |
initialValue() |
static <T> CleaningThreadLocal<T> |
withCleanup(Supplier<T> supplier,
ThrowingConsumer<T,Exception> cleanup) |
static <T> CleaningThreadLocal<T> |
withCleanup(Supplier<T> supplier,
ThrowingConsumer<T,Exception> cleanup,
Function<T,T> getWrapper) |
static <T> CleaningThreadLocal<T> |
withCleanup(ThrowingConsumer<T,Exception> cleanup) |
static <T> CleaningThreadLocal<T> |
withCloseQuietly(Supplier<T> supplier) |
remove, set, withInitial
public static <T> CleaningThreadLocal<T> withCloseQuietly(Supplier<T> supplier)
public static <T> CleaningThreadLocal<T> withCleanup(ThrowingConsumer<T,Exception> cleanup)
public static <T> CleaningThreadLocal<T> withCleanup(Supplier<T> supplier, ThrowingConsumer<T,Exception> cleanup)
public static <T> CleaningThreadLocal<T> withCleanup(Supplier<T> supplier, ThrowingConsumer<T,Exception> cleanup, Function<T,T> getWrapper)
protected T initialValue()
initialValue
in class ThreadLocal<T>
public T get()
get
in class ThreadLocal<T>
public void cleanup(T value)
value
- value to clean up forCopyright © 2021. All rights reserved.