IBM Support

JAXBContext Initialization Takes A Long Time

Technote (troubleshooting)


JAXBContext initialization slows down application performance.


Slow performance in WebSphere Application Server.


JAXB context (javax.xml.bind.JAXBContext) object instantiation is a resource intensive operation. JAXB Context instantiation involves the pre-load and pre-creation of contexts (called the pre-caching process) of all packages and classes associated with the context, and then all of the packages and classes which are statically (directly and indirectly) referenced from those. Performance latency will correlate with the number of classes which are passed during JAXB creation during this pre-caching process.

Diagnosing the problem

Thread dumps collected during performance latency will show many instances of "JAXBContext.newInstance".

Resolving the problem

Singleton JAXB Implementation:

If an application requires heavy use of a single JAXBContext, the application should implement the singleton model of the JAXBContext instance. In the singleton model, re-using a particular JAXB context (which is bound to a set of classes/packages) in a repeated manner will drastically reduce JVM effort on pre-load and pre-creation of contexts..

For example, implement a get() method which only returns a single instance of the JAXB context. Then re-use this reference wherever this context is required.

newInstance() JAXB Implementation
If an application requires the use of heterogenous JAXBContexts (contexts which are bound to different classes / packages) where each context operates in a limited manner, the application will need to make use of multiple JAXBContext instances. Implementing JAXBContext.newInstance() creates a new JAXBContext at each invocation. Heavy use of JAXBContext.newInstance() comes with the performance trade-off caused by the repeated context initialization. The effect of the initialization delay is directly correlated to the number of JAXBContext objects created.

Disabling Pre-Caching And Optimization Mechanisms
With each JAXBContext initialization, pre-caching and optimization mechanisms can be disabled by specifying specific JVM System Properties (see below). Please note that when the pre-caching mechanism is disabled, the runtime marshaller / un-marshaller using the pre-cached metadata will be impacted adversely. Here the rule-of-thumb for determining an appropriate pre-caching feature for an application is based on the re-usability of the JAXB context(s):

  • If the re-use factor is high, enable pre-caching (a slow boot, but boosted runtime performance).
  • For heterogenous and non-repeatable JAXB operations, disable pre-caching to gain boot time performance.

JVM System Properties to Disable Pre-Caching
    WAS 7.0 users (JAXB within JDK6 bundled by WAS):
    WAS 8.x users (JAXB within JAX-RI bundled with WAS):

    Liberty Users :
    Non-WAS product users (JAXB bundled within JDK 6 / JDK7):
    Non-WAS product users (JAXB RI outside JDK 6 / JDK7):
    Disclaimer : Please note the above mentioned JVM properties are non-public and undocumented JAXB internal implementation properties. Future releases of JAXB may not support these properties. Also note that these properties have system wide scope which means all of the JAXB operations will be affected.

    *see below for related JAXB documentation

    Related information

    JAXB - WAS ND Documentation 8.5 JAXB 2.2
    JAXB - WAS ND Documentation 8.0 JAXB 2.2 (New Feature)
    Java Architecture for XML Binding (JAXB) 2.0 specificat
    Class JAXBContext

    Document information

    More support for: WebSphere Application Server

    Software version: 7.0, 8.0, 8.5, 8.5.5

    Operating system(s): AIX, HP-UX, Linux, Solaris, Windows

    Reference #: 1641260

    Modified date: 27 September 2013

    Translate this page: