IBM Support

JAXBContext Initialization Takes A Long Time

Troubleshooting


Problem

JAXBContext initialization slows down application performance.

Symptom

Slow performance in WebSphere Application Server.

Cause

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):
      com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.fastBoot=true
      com.sun.xml.internal.bind.v2.bytecode.ClassTailor.noOptimize=true
    WAS 8.x users (JAXB within JAX-RI bundled with WAS):
      com.ibm.jtc.jax.xml.bind.v2.runtime.JAXBContextImpl.fastBoot=true 
      com.ibm.jtc.jax.xml.bind.v2.bytecode.ClassTailor.noOptimize=true

    Liberty Users :
      com.sun.xml.bind.v2.runtime.JAXBContextImpl.fastBoot=true 
      com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true
    Non-WAS product users (JAXB bundled within JDK 6 / JDK7):
      com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.fastBoot=truecom.sun.xml.internal.bind.v2.bytecode.ClassTailor.noOptimize=true
    Non-WAS product users (JAXB RI outside JDK 6 / JDK7):
      com.sun.xml.bind.v2.runtime.JAXBContextImpl.fastBoot=true 
      com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true
    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

    [{"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF010","label":"HP-UX"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.5.5;8.5;8.0;7.0","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

    Document Information

    Modified date:
    15 June 2018

    UID

    swg21641260