Class DetachedThreadLocal<T>
- java.lang.Object
-
- org.mockito.internal.util.concurrent.DetachedThreadLocal<T>
-
- All Implemented Interfaces:
java.lang.Runnable
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DetachedThreadLocal.Cleaner
Determines the cleaning format.
-
Field Summary
Fields Modifier and Type Field Description (package private) WeakConcurrentMap<java.lang.Thread,T>
map
-
Constructor Summary
Constructors Constructor Description DetachedThreadLocal(DetachedThreadLocal.Cleaner cleaner)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
Field Detail
-
map
final WeakConcurrentMap<java.lang.Thread,T> map
-
-
Constructor Detail
-
DetachedThreadLocal
public DetachedThreadLocal(DetachedThreadLocal.Cleaner cleaner)
-
-
Method Detail
-
get
public T get()
-
get
public T get(java.lang.Thread thread)
- Parameters:
thread
- The thread for which to set a thread-local value.- Returns:
- The value associated with this thread.
-
set
public void set(T value)
-
clear
public void clear()
-
clearAll
public void clearAll()
Clears all thread local references for all threads.
-
pushTo
public T pushTo(java.lang.Thread thread)
- Parameters:
thread
- The thread to which this thread's thread local value should be pushed.- Returns:
- The value being set.
-
fetchFrom
public T fetchFrom(java.lang.Thread thread)
- Parameters:
thread
- The thread from which the thread thread local value should be fetched.- Returns:
- The value being set.
-
define
public void define(java.lang.Thread thread, T value)
- Parameters:
thread
- The thread for which to set a thread-local value.value
- The value to set.
-
initialValue
protected T initialValue(java.lang.Thread thread)
- Parameters:
thread
- The thread for which an initial value is created.- Returns:
- The initial value for any thread local. If no default is set, the default value is
null
.
-
inheritValue
protected T inheritValue(T value)
- Parameters:
value
- The value that is inherited.- Returns:
- The inherited value.
-
getBackingMap
public WeakConcurrentMap<java.lang.Thread,T> getBackingMap()
- Returns:
- The weak map that backs this detached thread local.
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
-