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
files.
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
expected:
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
expected:
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.