public abstract class ThreadLocalSoft<T> extends Object implements Closeable
Using ThreadLocal internally, there are leak pitfalls, you must use one of the following modes. (1) static, the only Ref in JVM, to avoid creating temporary Ref multiple times. (2) use try-finally-close mode to remove the Ref.
| Constructor and Description |
|---|
ThreadLocalSoft(ThreadLocal<SoftReference<T>> threadLocal) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
anewValue(T t)
Reset to current value in a single thread and decide whether it is available
|
void |
close() |
abstract T |
initValue()
Init in a single thread, first time or anewValue() call
|
T |
use()
(1) static, the only Ref in JVM, to avoid creating temporary Ref multiple times.
|
public ThreadLocalSoft(ThreadLocal<SoftReference<T>> threadLocal) throws ThreadLocalAttention
ThreadLocalAttention@NotNull public abstract T initValue()
public boolean anewValue(@NotNull
T t)
t - current value@NotNull public T use()
(1) static, the only Ref in JVM, to avoid creating temporary Ref multiple times. (2) use try-finally-close mode to remove the Ref.
public void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2024. All rights reserved.