Class clazz = null;
if (classCache != null)
{
ConcurrentHashMap subCache = (ConcurrentHashMap )classCache.get(Thread.currentThread().getContextClassLoader());
if (subCache==null)
{
classCache.put(Thread.currentThread().getContextClassLoader(), new ConcurrentHashMap());
subCache = (ConcurrentHashMap )classCache.get(Thread.currentThread().getContextClassLoader());
}
WeakReference ref = (WeakReference) subCache.get(className);
if (ref != null)
{
clazz = (Class) ref.get();
}
if (clazz == null)
{
if (ref != null) subCache.remove(className);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try
{
clazz = loader.loadClass(className);
}
catch (ClassNotFoundException e)
{
/* Use the Class.forName call which will resolve array classes. We
do not use this by default as this can result in caching of stale
values across redeployments.
*/
clazz = Class.forName(className, false, loader);
}
subCache.put(className, new WeakReference(clazz));
}
}
else
{
clazz = Thread.currentThread().getContextClassLoader().loadClass(className);