Strange java.beans.Introspector behavior on WebLogic with DCEVM and HotSwapAgent

孤者浪人 提交于 2019-12-05 15:56:22
Martin Macak

Found this thanks to @ddekany and his answer to related problem at Freemarker removeIntrospectionInfo does not work with DCEVM after model hotswap

It seems that JVM (at least HotSpot 1.7) caches Introspector's cache per ThreadGroup. This means, that Introspector.flushCaches must be called in a thread that runs in corresponding ThreadGroup.

When I executed this for all the ThreadGroups in the application then everything started working again properly.

I wasn't able to find any documentation why the java.beans.Introspector is cached per ThreadGroup so if anybody has an reliable information to this, please add a comment with link.

Thanks.

Update:

Comming from JDK7 source

/**
     * 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;
    }

This has been definitely added in JDK7, because I checked JDK6 code and it's not there!.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!