java.lang

Class InheritableThreadLocal<T>

public class InheritableThreadLocal<T> extends ThreadLocal<T>

A ThreadLocal whose value is inherited by child Threads. The value of the InheritableThreadLocal associated with the (parent) Thread is copied to the new (child) Thread at the moment of creation.

It is possible to make the value associated with the child Thread a function of the value that is associated with the parent Thread by overriding the childValue() method. The utility of this class is in transferring items like User ID or Transaction ID across threads automatically.

Since: 1.2

See Also: ThreadLocal

UNKNOWN: updated to 1.4

Constructor Summary
InheritableThreadLocal()
Creates a new InheritableThreadLocal that has no values associated with it yet.
Method Summary
protected TchildValue(T parentValue)
Determines the value associated with a newly created child Thread as a function of the value associated with the currently executing (parent) Thread.

Constructor Detail

InheritableThreadLocal

public InheritableThreadLocal()
Creates a new InheritableThreadLocal that has no values associated with it yet.

Method Detail

childValue

protected T childValue(T parentValue)
Determines the value associated with a newly created child Thread as a function of the value associated with the currently executing (parent) Thread. The default implementation just returns the parentValue.

Parameters: parentValue the value of this object in the parent thread at the moment of creation of the child

Returns: the initial value for the child thread