This class provides invocation-scope variables.
The mechanism operates similarly to
ThreadLocal. These variables differ from their
normal counterparts in that code in an invocation that accesses one (via its
has its own, independently initialized copy of the variable.
are typically private static fields in classes that wish to associate state with an invocation.
Each invocation is associated with a copy of an invocation-scoped variable as long as the
invocation is in progress and the
InvocationLocal instance is accessible. After an
invocation is complete, all of its copies of invocation-local instances are subject to garbage
collection (unless other references to these copies exist).
Note that unlike
ThreadLocal instances that are no longer referenced while the
invocation is still in progress are not garbage collected. Creating local or non-static instances
is therefore not recommended as they could grow without bound.
Warning: Use this class sparingly as invocation-locals are glorified global variables with many of the same pitfalls.
Returns the currently-executing invocation's copy of this invocation-local variable.
Returns the current invocation's "initial value" for this invocation-local variable.
public InvocationLocal ()
public final T get ()
Returns the currently-executing invocation's copy of this invocation-local variable. If the
variable has no value for the current invocation, it is first initialized to the value
returned by a call to the
|the currently executing invocation's copy of this invocation-local.
protected T initialValue ()
Returns the current invocation's "initial value" for this invocation-local variable. This
method will be invoked the first time code executing in the context of the invocation
accesses the variable with the
get() method. This method is guaranteed to be invoked
at most once per invocation.
This implementation simply returns
null but can be changed by sub-classing
InvocationLocal and overriding this method.
|the initial value for this invocation-scoped variable