public class JDKThreadLocal<T> extends ContextLocalBase<T> implements ContextLocal<T>
Implement ContextLocal using JDK ThreadLocal
ContextLocal.Factory, ContextLocal.InitialValueProvider<T>CONF_CONTEXT_LOCAL_FACTORY| Constructor and Description |
|---|
JDKThreadLocal() |
JDKThreadLocal(ContextLocal.InitialValueProvider<T> ivp) |
| Modifier and Type | Method and Description |
|---|---|
T |
get()
Returns the value in the current context’s copy of this context-local variable.
|
void |
remove()
Removes the current context’s value for this context-local variable.
|
void |
set(T value)
Sets the current context’s copy of this context-local variable to the specified value.
|
initialValueapplybreakOutclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitinitialValuepublic JDKThreadLocal()
public JDKThreadLocal(ContextLocal.InitialValueProvider<T> ivp)
public T get()
ContextLocalReturns the value in the current context’s copy of this context-local variable. If the variable has no value for the current context, it is first initialized to the value returned by an invocation of the ContextLocal.initialValue() method.
get in interface ContextLocal<T>public void set(T value)
ContextLocalSets the current context’s copy of this context-local variable to the specified value. Most subclasses will have no need to override this method, relying solely on the ContextLocal.initialValue() method to set the values of context-locals.
set in interface ContextLocal<T>value - the value to be stored in the current context’s copy of this context-local.public void remove()
ContextLocalRemoves the current context’s value for this context-local variable. If this context-local variable is subsequently read by the current thread, its value will be reinitialized by invoking its ContextLocal.initialValue() method, unless its value is set by the current context in the interim. This may result in multiple invocations of the initialValue method in the current context.
remove in interface ContextLocal<T>Copyright © 2014–2021 OSGL (Open Source General Library). All rights reserved.