感谢@ddekany 和他在Freemarker removeIntrospectionInfo 对相关问题的回答在模型热交换后无法与 DCEVM 一起工作
似乎 JVM(至少 HotSpot 1.7)为每个 ThreadGroup 缓存了 Introspector 的缓存。这意味着,Introspector.flushCaches
必须在相应的ThreadGroup
.
当我为应用程序中的所有线程组执行此操作时,一切都开始正常工作。
我找不到任何文档为什么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 代码并且它不存在!