0
我有以下问题。
A HashMap
用于设置属性,关键是ClassLoader
。
,设置属性的代码如下(AxisProperties
):在这种情况下将使用哪个类加载器?
public static void setProperty(String propertyName, String value, boolean isDefault){
if(propertyName != null)
synchronized(propertiesCache)
{
ClassLoader classLoader = getThreadContextClassLoader();
HashMap properties = (HashMap)propertiesCache.get(classLoader);
if(value == null)
{
if(properties != null)
properties.remove(propertyName);
} else
{
if(properties == null)
{
properties = new HashMap();
propertiesCache.put(classLoader, properties);
}
properties.put(propertyName, new Value(value, isDefault));
}
}
}
其中一个值是缓存的地方,我需要重置此HashMap,但问题是我不知道如何做到这一点。
我想加载类(委托给axis
使用URLClassLoader
),但我看到的代码确实getThreadContextClassLoader();
是:
public ClassLoader getThreadContextClassLoader()
{
ClassLoader classLoader;
try
{
classLoader = Thread.currentThread().getContextClassLoader();
}
catch(SecurityException e)
{
classLoader = null;
}
return classLoader;
}
因此,我认为它会用我的当前线程不是一个的类加载器是我曾经加载要使用的类(即axis
)。
那么有没有办法解决这个问题?
注:我已经装载axis
作为我的应用程序的一部分。这样的想法是通过不同的类加载器加载它
你是什么propertiesCache的大小?我真的期望它是1,是吗? –
@GermannArlington:我真的不知道。我只设置了1个属性,所以除非'Axis'将其他内容放在哈希表中,否则我只能假设** 1条目。我设置的和OP是关于 – Jim
如果只有一个条目在这里有一个HashMap的意义何在? P.S.你总是可以迭代地图中的所有条目来找到你所拥有的。 –