public class DetachedThreadLocal<T>
extends java.lang.Object
implements java.lang.Runnable
A detached local that allows for explicit control of setting and removing values from a thread-local context.
Instances of this class are non-blocking and fully thread safe.Modifier and Type | Class and Description |
---|---|
static class |
DetachedThreadLocal.Cleaner
Determines the cleaning format.
|
Modifier and Type | Field and Description |
---|---|
(package private) WeakConcurrentMap<java.lang.Thread,T> |
map |
Constructor and Description |
---|
DetachedThreadLocal(DetachedThreadLocal.Cleaner cleaner) |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
void |
clearAll()
Clears all thread local references for all threads.
|
void |
define(java.lang.Thread thread,
T value) |
T |
fetchFrom(java.lang.Thread thread) |
T |
get() |
T |
get(java.lang.Thread thread) |
WeakConcurrentMap<java.lang.Thread,T> |
getBackingMap() |
protected T |
inheritValue(T value) |
protected T |
initialValue(java.lang.Thread thread) |
T |
pushTo(java.lang.Thread thread) |
void |
run() |
void |
set(T value) |
final WeakConcurrentMap<java.lang.Thread,T> map
public DetachedThreadLocal(DetachedThreadLocal.Cleaner cleaner)
public T get()
public void set(T value)
public void clear()
public void clearAll()
public T pushTo(java.lang.Thread thread)
thread
- The thread to which this thread's thread local value should be pushed.public T fetchFrom(java.lang.Thread thread)
thread
- The thread from which the thread thread local value should be fetched.public T get(java.lang.Thread thread)
thread
- The thread for which to set a thread-local value.public void define(java.lang.Thread thread, T value)
thread
- The thread for which to set a thread-local value.value
- The value to set.protected T initialValue(java.lang.Thread thread)
thread
- The thread for which an initial value is created.null
.protected T inheritValue(T value)
value
- The value that is inherited.public WeakConcurrentMap<java.lang.Thread,T> getBackingMap()
public void run()
run
in interface java.lang.Runnable