Package org.apache.calcite.util
Class TryThreadLocal<T>
- java.lang.Object
-
- java.lang.ThreadLocal<T>
-
- org.apache.calcite.util.TryThreadLocal<T>
-
- Type Parameters:
T
- Value type
public class TryThreadLocal<T> extends java.lang.ThreadLocal<T>
Thread-local variable that returns a handle that can be closed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TryThreadLocal.Memo
Remembers to set the value back.
-
Field Summary
Fields Modifier and Type Field Description private T
initialValue
-
Constructor Summary
Constructors Modifier Constructor Description private
TryThreadLocal(T initialValue)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected T
initialValue()
static <T> TryThreadLocal<T>
of(T initialValue)
Creates a TryThreadLocal.TryThreadLocal.Memo
push(T value)
Assigns the value asvalue
for the current thread.
-
-
-
Field Detail
-
initialValue
private final T initialValue
-
-
Constructor Detail
-
TryThreadLocal
private TryThreadLocal(T initialValue)
-
-
Method Detail
-
of
public static <T> TryThreadLocal<T> of(T initialValue)
Creates a TryThreadLocal.- Parameters:
initialValue
- Initial value
-
initialValue
protected final T initialValue()
- Overrides:
initialValue
in classjava.lang.ThreadLocal<T>
-
push
public TryThreadLocal.Memo push(T value)
Assigns the value asvalue
for the current thread. Returns aTryThreadLocal.Memo
which, when closed, will assign the value back to the previous value.
-
-