Package org.apache.calcite.util
Class TryThreadLocal<T>
java.lang.Object
java.lang.ThreadLocal<@Nullable T>
org.apache.calcite.util.TryThreadLocal<T>
- Type Parameters:
T
- Value type
Thread-local variable that returns a handle that can be closed.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Remembers to set the value back. -
Method Summary
Modifier and TypeMethodDescriptionget()
protected final T
void
Performs an action with this ThreadLocal set to a particular value in this thread, and restores the previous value afterwards.<R> R
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.Assigns the value asvalue
for the current thread.protected void
Sets the value back to a previous value.Methods inherited from class java.lang.ThreadLocal
remove, set, withInitial
-
Method Details
-
of
Creates a TryThreadLocal.- Parameters:
initialValue
- Initial value
-
initialValue
- Overrides:
initialValue
in classThreadLocal<@Nullable T>
-
get
- Overrides:
get
in classThreadLocal<@Nullable T>
-
push
Assigns the value asvalue
for the current thread. Returns aTryThreadLocal.Memo
which, when closed, will assign the value back to the previous value. -
restoreTo
Sets the value back to a previous value.If the previous value was
initialValue
, callsThreadLocal.remove()
. There's no way to tell whetherThreadLocal.set(T)
has been called previously, but the effect is the same. -
letIn
Performs an action with this ThreadLocal set to a particular value in this thread, and restores the previous value afterwards.This method is named after the Standard ML
let
construct, for examplelet val x = 1 in x + 2 end
. -
letIn
Calls a Supplier with this ThreadLocal set to a particular value, in this thread, and restores the previous value afterwards.This method is named after the Standard ML
let
construct, for examplelet val x = 1 in x + 2 end
.
-