我使用DCEVM (完全实现)在JVM1.7上运行WebLogic,使用在每个onClassLoad上触发的定制插件运行HotSwapAgent。
我遇到了使用java.beans.Introspector的Freemarker的问题。我发现的事实是,当我在HotSwapAgent调用的方法上调用HotSwapAgent(通过ReflectionCommand)时,Introspector中的BeanInfo将被正确地失效(在该线程中使用调试器进行检查)。但是,当我向WLS应用服务器发出请求时,工作线程的Introspector将显示旧值!
这似乎是一些线程本地实现,但我无法在java.beans.Introspector的文档中找到指向该假设的任何内容。
有没有人知道为什么会发生这种情况,以及如何解决这个问题?
目前,我将有关重新加载类的信息存储在单独的类中,并从请求线程重新加载缓存中的所有内容,该请求线程可以工作。
谢谢你的任何线索。
发布于 2015-03-01 17:24:53
这要感谢@ddekany和他对Freemarker removeIntrospectionInfo does not work with DCEVM after model hotswap相关问题的回答。
JVM (至少是HotSpot 1.7)在每个ThreadGroup上缓存Introspector的缓存。这意味着,必须在运行在相应的Introspector.flushCaches中的线程中调用ThreadGroup。
当我对应用程序中的所有ThreadGroups执行此操作时,一切都再次正常工作。
我无法找到任何文件,为什么java.beans.Introspector被缓存在每个ThreadGroup,所以如果有人有可靠的信息,请添加一个链接的评论。
谢谢。
更新:
从JDK7源开始
/**
* Introspect on a Java Bean and learn about all its properties, exposed
* methods, and events.
* <p>
* If the BeanInfo class for a Java Bean has been previously Introspected
* then the BeanInfo class is retrieved from the BeanInfo cache.
*
* @param beanClass The bean class to be analyzed.
* @return A BeanInfo object describing the target bean.
* @exception IntrospectionException if an exception occurs during
* introspection.
* @see #flushCaches
* @see #flushFromCaches
*/
public static BeanInfo getBeanInfo(Class<?> beanClass)
throws IntrospectionException
{
if (!ReflectUtil.isPackageAccessible(beanClass)) {
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
}
ThreadGroupContext context = ThreadGroupContext.getContext();
BeanInfo beanInfo;
synchronized (declaredMethodCache) {
beanInfo = context.getBeanInfo(beanClass);
}
if (beanInfo == null) {
beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo();
synchronized (declaredMethodCache) {
context.putBeanInfo(beanClass, beanInfo);
}
}
return beanInfo;
}这肯定是在JDK7中添加的,因为我检查了JDK6代码,但它不在那里!
https://stackoverflow.com/questions/28768348
复制相似问题