Class ReentrantThreadLocal<T>
java.lang.Object
dev.getelements.elements.sdk.util.ReentrantThreadLocal<T>
- Type Parameters:
T
-
Backed by a
ThreadLocal<T>
, this allows for the creation of a thread-local scope which can be entered and
exited multiple times, provided that the underlying calls are balanced.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Ensures that the current value is empty, throwing an instance ofIllegalStateException
if the object is not in scope.Enters scope with the supplied value of T.Gets the current value throwing an instance ofIllegalStateException
if there is not a current value.
-
Constructor Details
-
ReentrantThreadLocal
public ReentrantThreadLocal()Creates a newReentrantThreadLocal<T>
-
-
Method Details
-
getCurrent
Gets the current value throwing an instance ofIllegalStateException
if there is not a current value.- Returns:
- the current value.
-
getCurrentOptional
-
ensureEmpty
public void ensureEmpty()Ensures that the current value is empty, throwing an instance ofIllegalStateException
if the object is not in scope. -
enter
Enters scope with the supplied value of T.- Parameters:
t
- the value of t- Returns:
- a
ReentrantThreadLocal.Scope
which will hold the value until it is closed, reverting it to the previous value.
-