T - Value typepublic class TryThreadLocal<T> extends ThreadLocal<T>
| Modifier and Type | Class and Description |
|---|---|
static interface |
TryThreadLocal.Memo
Remembers to set the value back.
|
| Modifier and Type | Method and Description |
|---|---|
protected T |
initialValue() |
void |
letIn(T t,
Runnable runnable)
Performs an action with this ThreadLocal set to a particular value
in this thread, and restores the previous value afterwards.
|
<R> R |
letIn(T t,
Supplier<R> supplier)
Calls a Supplier with this ThreadLocal set to a particular value,
in this thread, and restores the previous value afterwards.
|
static <T> TryThreadLocal<T> |
of(T initialValue)
Creates a TryThreadLocal.
|
TryThreadLocal.Memo |
push(T value)
Assigns the value as
value for the current thread. |
protected void |
restoreTo(T previous)
Sets the value back to a previous value.
|
get, remove, set, withInitialpublic static <T> TryThreadLocal<T> of(T initialValue)
initialValue - Initial valueprotected final T initialValue()
initialValue in class ThreadLocal<T>public TryThreadLocal.Memo push(T value)
value for the current thread.
Returns a TryThreadLocal.Memo which, when closed, will assign the value
back to the previous value.protected void restoreTo(T previous)
If the previous value was initialValue, calls
ThreadLocal.remove(). There's no way to tell whether ThreadLocal.set(T) has
been called previously, but the effect is the same.
public void letIn(T t, Runnable runnable)
This method is named after the Standard ML let construct,
for example let val x = 1 in x + 2 end.
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.