Improving application startup in Liberty
You can substantially improve the startup of applications by having Liberty read Jandex index files to obtain class and annotation data for application archives. Reading these index files is a substantial performance improvement over scanning the bytecodes of the classes within the archives.
Before you begin
- Jandex is a class and annotation index API that you can use to generate and store Jandex index
You must use the available Jandex APIs to place Jandex index files into applications since Liberty does not generate Jandex index files.
Liberty supports Jandex V2.0.3. Jandex v2.0.3 artifacts are available from Maven.
For more information about how to place Jandex index files into applications, see the section on creating a persisted index by using the command-line interface (CLI) in the Jandex readme file in GITHUB.
You can find more comprehensive examples at, for instance, Java How To.
- Put Jandex index files in applications before you install these applications on Liberty.
The standard location for Jandex index files is the META-INF/jandex.idx path for all archive types, including WAR files. EAR files do not receive immediate child Jandex index files since they do not directly package class resources.
- For Jandex index files to be effective, place the files in all application archives.
For a simple JAR type archive, such as for an application client JAR file or for an EJB JAR file, a single Jandex index file is generated for the JAR file. For RAR and WAR archives, a Jandex index file is generated both for the RAR or WAR and also for every JAR file that is present within the RAR or WAR. Liberty does not support whole archive indexes for RAR and WAR files.
- For example, for an EJB JAR file, this archive structure is
myEjbJar.jar/ META-INF/ejb-jar.xml META-INF/jandex.idx com/mycompany/framework/MyClass.class
- For example, for a WAR file, this archive structure is
myWAR.war/ META-INF/jandex.idx WEB-INF/web.xml WEB-INF/classes/com/mycompany/framework1/MyClass1.class WEB-INF/lib/myJar.jar/ META-INF/jandex.idx com/mycompany/framework2/MyClass2.class
- You can populate some or none of the archives of an application with Jandex index files. The startup reduction is in proportion to the percentage of the archives that are populated with Jandex index files. For archives that do not have Jandex index files, Liberty scans the bytecode of the classes within the archives, which increases the application startup time.
- For example, for an EJB JAR file, this archive structure is expected:
About this task
Normally, Liberty obtains class and annotation data for application archives by performing a bytecode scan of the classes within the archives. This expensive process iterates across all of the classes within target archives and reads, decodes, and processes bytecodes for each of the classes. When Jandex reading is enabled, Liberty preferentially reads any Jandex index file available within target application archives instead of performing the expensive iterative class scan. Reading a Jandex index file is much faster than scanning classes iteratively, resulting in a substantial performance improvement.
By default, Jandex support is disabled to guard against invalid Jandex index files, such as when classes of an application archive are more recent than the Jandex index file of the archive.
The following procedure explains how to enable Jandex support.
To enable Jandex support for all applications, set the useJandex element on the application
manager element to true.
Use the following example as a guide:
<applicationManager autoExpand="true" useJandex="true"/>
To enable Jandex support for a single application, set the useJandex element on the application
element to true.
Use the following example as a guide:
<webApplication location="TestApp.war" type="war" useJandex="true"/>
To enable Jandex support for all but one application, set the useJandex element on the
application manager element to true and the useJandex element on one application
element to false.
Use the following example as a guide:You can disable Jandex support for additional applications by setting the useJandex element on each additional application element to false.
<applicationManager autoExpand="true" useJandex="true"/> <webApplication location="TestApp.war" type="war" useJandex="false"/>