Performance issues when calling java.beans.Introspector.getBeanInfo after inactivity

I use a third-party library that dynamically instantiates Java classes and populates these instances with Introspector.getBeanInfo. Some queries may result in 5 or 6 consecutive calls Introspector.getBeanInfo. I found that when the application is idle for about an hour or so, the first call Introspector.getBeanInfotakes significantly longer to complete (20-60 seconds) and subsequent calls (<100 milliseconds). Calls made over the next few minutes continue to take <100 milliseconds, but when I wait another hour, the first call again takes 20-60 seconds.

In an attempt to recreate the behavior with a simple test application, I found a similar behavior when the java application does not start for an hour. For example, if I run the following console application, it may take 15 milliseconds. If I then wait an hour and run the application again, it will take 20 seconds.

long start = System.currentTimeMillis();
System.out.println("Start");
Introspector.getBeanInfo(MyClass.class, Object.class);
long end = System.currentTimeMillis();
System.out.println("End: " + (end-start));

Initially, I thought the problem might be that the Introspector class is trying to create class instances based on standard naming conventions that do not exist in my application (for example MyClassBeanInfo), and it took a long time to scan jar files in an attempt to find these classes (my java application has a little over 100 references to jar files), but I called Introspector.getBeanInfo(MyClass.class, Object.class, Introspector.IGNORE_ALL_BEANINFO)using reflection (this is a private method in Sun JRE, which, from viewing the code, seems to skip searching for BeanInfo classes), and I was still able to reproduce the delay .

I also searched for information about any type of JRE / JVM JAR cache, but have not yet found anything that seems to explain this behavior. Does anyone know why this behaves the way it is done, and if I can do something to fix it?

JDK 1.6.0_21 Windows XP. , , - BlazeDS. Tomcat Spring/BlazeDS. BlazeDS, , ( Introspector.getBeanInfo getPropertyDescriptorCacheEntry flex.messaging.io.BeanProxy). , BlazeDS BeanInfo, Introspector.getBeanInfo , Blaze , Java, . , , , .

EDIT: jstack ( @Tom) , jar. 5 20 ( ) :

"http-8080-exec-6" daemon prio=6 tid=0x65cae800 nid=0x1a50 runnable [0x67a3d000]
   java.lang.Thread.State: RUNNABLE
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(Unknown Source)
    at java.util.jar.JarFile.<init>(Unknown Source)
    at java.util.jar.JarFile.<init>(Unknown Source)
    at org.apache.catalina.loader.WebappClassLoader.openJARs(WebappClassLoader.java:2704)
    at org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2945)
    - locked <0x1804cc18> (a [Ljava.util.jar.JarFile;)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2739)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1144)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1639)
    - locked <0x1803dd38> (a org.apache.catalina.loader.WebappClassLoader)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1517)
    at java.beans.Introspector.instantiate(Unknown Source)
    at java.beans.Introspector.findExplicitBeanInfo(Unknown Source)
    - locked <0x434649a0> (a java.lang.Class for java.beans.Introspector)
    at java.beans.Introspector.<init>(Unknown Source)
    at java.beans.Introspector.getBeanInfo(Unknown Source)
    - locked <0x181bed70> (a java.lang.Object)

, - JRE/JVM jar, jar , - , .

EDIT: , Tomcat WebappClassLoader JAR . , , ...

EDIT: Tomcat JAR 90 jar. WebappClassLoader , jar . jar , . , , JAR/JVM, -, ( , ..), . ...

+5
3

. Introspector , (, ClassLoader) *BeanInfo, , , Introspector .

, BeanInfo , , . , , , ClassLoader , , Tomcat.

BeanInfo , Introspector, , .

+3

java.beans.Introspector OSGi, . Equinox - : Eclipse-BuddyPolicy: depenent Eclipse-BuddyPolicy: global .

java.beans.Introspector

  • org.apache.log4j.config.PropertySetter
  • org.springframework.beans.CachedIntrospectionResults
  • org.hibernate.util.Cloneable#copyListeners

, Introspector Equinox, Introspector.IGNORE_ALL_BEANINFO. , JVM Oracle BeanInfo , Introspector.USE_ALL_BEANINFO. , , javadocs, , Introspector ( ).

+1

, WebAppClassLoader Tomcat JAR 90 . Introspector.getBeanInfo 90 , Tomcat JAR. , . , .

, WebAppClassLoader JAR . , Tomcat , -, Tomcat, -. , .

JAR (cacheJarFiles - , WebAppClassLoader):

private static boolean cacheJarFiles = true;

...

public void closeJARs(boolean force) {
   if (cacheJarFiles) {
      return;
   }
   if (jarFiles.length > 0) {
      synchronized (jarFiles) {
         if (force || (System.currentTimeMillis() 

...

}

, closeJARs. , , . 10-60 + Introspector.getBeanInfo. 100-200 .

0
source

All Articles