jodd.util
Class ClassLoaderLocal<T>

java.lang.Object
  extended by jodd.util.ClassLoaderLocal<T>

public class ClassLoaderLocal<T>
extends java.lang.Object

This class provides classloader-local variables.

It is designed to look very much like ThreadLocal.


Constructor Summary
ClassLoaderLocal()
           
 
Method Summary
 T get()
          Returns the value in the current classloader copy of this variable.
protected  T initialValue()
          Returns the current classloader "initial value" for this classloader-local variable.
 void remove()
          Removes the current classloader's value for this variable.
 void set(T value)
          Sets the current classloaders's copy of this variable to the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLoaderLocal

public ClassLoaderLocal()
Method Detail

initialValue

protected T initialValue()
Returns the current classloader "initial value" for this classloader-local variable. This method will be invoked the first time it is accessed the get() method, unless the thread previously invoked the set(T) method, in which case the initialValue method will not be invoked for the classloader. Normally, this method is invoked at most once per classloader, but it may be invoked again in case of subsequent invocations of remove() followed by get().

This implementation simply returns null; if the programmer desires classloader-local variables to have an initial value other than null, ClassLoaderLocal must be subclassed, and this method overridden. Typically, an anonymous inner class will be used.


get

public T get()
Returns the value in the current classloader copy of this variable. If the variable has no value for the current classloader, it is first initialized to the value returned by an invocation of the initialValue() method.


set

public void set(T value)
Sets the current classloaders's copy of this variable to the specified value. Most subclasses will have no need to override this method, relying solely on the initialValue() method to set the values of classloader-locals.


remove

public void remove()
Removes the current classloader's value for this variable.



Copyright © 2003-2012 Jodd Team