org.apache.commons.beanutils

Class 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:
java.lang.Thread.getContextClassLoader

Field Summary

private Object
globalValue
private boolean
globalValueInitialized
private Map
valueByClassLoader

Constructor Summary

ContextClassLoaderLocal()

Method Summary

Object
get()
Gets the instance which provides the functionality for BeanUtils.
protected Object
initialValue()
Returns the initial value for this ContextClassLoaderLocal variable.
void
set(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(ClassLoader classLoader)
Unsets the value associated with the given classloader

Field Details

globalValue

private Object globalValue

globalValueInitialized

private boolean globalValueInitialized

valueByClassLoader

private Map valueByClassLoader

Constructor Details

ContextClassLoaderLocal

public ContextClassLoaderLocal()

Method Details

get

public 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

initialValue

protected 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

set

public void set(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(ClassLoader classLoader)
Unsets the value associated with the given classloader

Copyright (c) 2001-2004 - Apache Software Foundation