java.lang
Class InheritableThreadLocal<T>

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.lang.ThreadLocal sample code for java.lang.ThreadLocal definition code for java.lang.ThreadLocal <T>
      extended by java.lang.InheritableThreadLocal<T>

public class InheritableThreadLocal<T>
extends ThreadLocal sample code for java.lang.ThreadLocal definition code for java.lang.ThreadLocal <T>

This class extends ThreadLocal to provide inheritance of values from parent thread to child thread: when a child thread is created, the child receives initial values for all inheritable thread-local variables for which the parent has values. Normally the child's values will be identical to the parent's; however, the child's value can be made an arbitrary function of the parent's by overriding the childValue method in this class.

Inheritable thread-local variables are used in preference to ordinary thread-local variables when the per-thread-attribute being maintained in the variable (e.g., User ID, Transaction ID) must be automatically transmitted to any child threads that are created.

Since:
1.2
See Also:
ThreadLocal sample code for java.lang.ThreadLocal definition code for java.lang.ThreadLocal

Constructor Summary
InheritableThreadLocal sample code for java.lang.InheritableThreadLocal.InheritableThreadLocal() definition code for java.lang.InheritableThreadLocal.InheritableThreadLocal() ()
           
 
Method Summary
protected  T childValue sample code for java.lang.InheritableThreadLocal.childValue(T) definition code for java.lang.InheritableThreadLocal.childValue(T) (T parentValue)
          Computes the child's initial value for this inheritable thread-local variable as a function of the parent's value at the time the child thread is created.
 
Methods inherited from class java.lang.ThreadLocal sample code for java.lang.ThreadLocal definition code for java.lang.ThreadLocal
get sample code for java.lang.ThreadLocal.get() definition code for java.lang.ThreadLocal.get() , initialValue sample code for java.lang.ThreadLocal.initialValue() definition code for java.lang.ThreadLocal.initialValue() , remove sample code for java.lang.ThreadLocal.remove() definition code for java.lang.ThreadLocal.remove() , set sample code for java.lang.ThreadLocal.set(T) definition code for java.lang.ThreadLocal.set(T)
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

InheritableThreadLocal sample code for java.lang.InheritableThreadLocal() definition code for java.lang.InheritableThreadLocal()

public InheritableThreadLocal()
Method Detail

childValue sample code for java.lang.InheritableThreadLocal.childValue(T) definition code for java.lang.InheritableThreadLocal.childValue(T)

protected T childValue(T parentValue)
Computes the child's initial value for this inheritable thread-local variable as a function of the parent's value at the time the child thread is created. This method is called from within the parent thread before the child is started.

This method merely returns its input argument, and should be overridden if a different behavior is desired.

Parameters:
parentValue - the parent thread's value
Returns:
the child thread's initial value