Class InternalThreadLocal<V>
java.lang.Object
java.lang.ThreadLocal<V>
org.apache.dubbo.common.threadlocal.InternalThreadLocal<V>
InternalThreadLocal
A special variant of
ThreadLocal that yields higher access performance when accessed from a
InternalThread.
Internally, a InternalThread uses a constant index in an array, instead of using hash code and hash table,
to look for a variable. Although seemingly very subtle, it yields slight performance advantage over using a hash
table, and it is useful when accessed frequently.
This design is learning from which is in Netty.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddestroy()final Vget()Returns the current value for the current threadfinal Vfinal voidremove()Sets the value to uninitialized; a proceeding call to get() will trigger a call to initialValue().final voidremove(InternalThreadLocalMap threadLocalMap) Sets the value to uninitialized for the specified thread local map; a proceeding call to get() will trigger a call to initialValue().static voidRemoves allInternalThreadLocalvariables bound to the current thread.final voidSets the value for the current thread.static intsize()Returns the number of thread local variables bound to the current thread.Methods inherited from class java.lang.ThreadLocal
withInitial
-
Constructor Details
-
InternalThreadLocal
public InternalThreadLocal()
-
-
Method Details
-
removeAll
public static void removeAll()Removes allInternalThreadLocalvariables bound to the current thread. This operation is useful when you are in a container environment, and you don't want to leave the thread local variables in the threads you do not manage. -
size
public static int size()Returns the number of thread local variables bound to the current thread. -
destroy
public static void destroy() -
get
Returns the current value for the current thread- Overrides:
getin classThreadLocal<V>
-
getWithoutInitialize
-
set
Sets the value for the current thread.- Overrides:
setin classThreadLocal<V>
-
remove
public final void remove()Sets the value to uninitialized; a proceeding call to get() will trigger a call to initialValue().- Overrides:
removein classThreadLocal<V>
-
remove
Sets the value to uninitialized for the specified thread local map; a proceeding call to get() will trigger a call to initialValue(). The specified thread local map must be for the current thread.
-