Java Class.forName slowed down due to Xml Annotations?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Max S
    New Member
    • Aug 2010
    • 1

    Java Class.forName slowed down due to Xml Annotations?

    I have a very large program that loops through about a thousand class strings and does Class.forName(. ..) on them. It is taking about 100+ milliseconds to execute forName(...) on the classes that have the annotation @XmlAccessorTyp e(XmlAccessType .NONE) and @XmlAttribute/@XmlElement tags on the class members. The classes that are not serializable to xml load in 0-5 milliseconds. I was wondering if any knew what that would be and if there is anyway to speed up the Class.forName(. ..) calls on these classes.

    Thanks

    Max
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Does this happen for each problematic class instance, or only the first one?

    Just pulling this out of the ether, but here goes....

    The reason I'm asking is that when you load a class with one of the @XmlAccessorTyp e annotations, it's going to force loading the XmlAccessorType class and its dependencies. If that class tree is complicated, it might be what's slowing down your load.

    You might try pre-loading XmlAccessorType , XmlAccessType, XmlAccessor, and XmlElement classes and maintainhandles to their class objects, so they don't unloaded. I don't know if it'll help or not.

    Comment

    Working...