org.apache.commons.beanutils
Class ContextClassLoaderLocal

java.lang.Object
  |
  +--org.apache.commons.beanutils.ContextClassLoaderLocal

public class ContextClassLoaderLocal
extends java.lang.Object

A value that is provided per (thread) context classloader. Patterned after ThreadLocal. There is a separate value used when Thread.getContextClassLoader() is null. This mechanism provides isolation for web apps deployed in the same container. Note: A WeakHashMap bug in several 1.3 JVMs results in a memory leak for those JVMs.

Author:
Eric Pabst
See Also:
Thread.getContextClassLoader()

Field Summary
private  java.lang.Object globalValue
           
private  boolean globalValueInitialized
           
private  java.util.Map valueByClassLoader
           
 
Constructor Summary
ContextClassLoaderLocal()
           
 
Method Summary
 java.lang.Object get()
          Gets the instance which provides the functionality for BeanUtils.
protected  java.lang.Object initialValue()
          Returns the initial value for this ContextClassLoaderLocal variable.
 void set(java.lang.Object value)
          Sets the value - a value is provided per (thread) context classloader.
 void unset()
          Unsets the value associated with the current thread's context classloader
 void unset(java.lang.ClassLoader classLoader)
          Unsets the value associated with the given classloader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueByClassLoader

private java.util.Map valueByClassLoader

globalValueInitialized

private boolean globalValueInitialized

globalValue

private java.lang.Object globalValue
Constructor Detail

ContextClassLoaderLocal

public ContextClassLoaderLocal()
Method Detail

initialValue

protected java.lang.Object initialValue()
Returns the initial value for this ContextClassLoaderLocal variable. This method will be called once per Context ClassLoader for each ContextClassLoaderLocal, the first time it is accessed with get or set. If the programmer desires ContextClassLoaderLocal variables to be initialized to some value other than null, ContextClassLoaderLocal must be subclassed, and this method overridden. Typically, an anonymous inner class will be used. Typical implementations of initialValue will call an appropriate constructor and return the newly constructed object.

Returns:
a new Object to be used as an initial value for this ContextClassLoaderLocal

get

public java.lang.Object get()
Gets the instance which provides the functionality for BeanUtils. This is a pseudo-singleton - an single instance is provided per (thread) context classloader. This mechanism provides isolation for web apps deployed in the same container.

Returns:
the object currently associated with the

set

public void set(java.lang.Object value)
Sets the value - a value is provided per (thread) context classloader. This mechanism provides isolation for web apps deployed in the same container.

Parameters:
value - the object to be associated with the entrant thread's context classloader

unset

public void unset()
Unsets the value associated with the current thread's context classloader


unset

public void unset(java.lang.ClassLoader classLoader)
Unsets the value associated with the given classloader



Copyright (c) 2001-2004 - Apache Software Foundation