English 中文(简体)
Java 10 - Class-Data Sharing
  • 时间:2024-11-05

Java 10 - Class-Data sharing

Previous Page Next Page  

JEP 310 − Apppcation Class-Data Sharing

When JVM starts it loads the classes in memory as a prepminary step. In case there are multiple jars having multiple classes, an evident lags appears for the first request. In serverless architecture, such a lag can delay the boot time which is a critical operation in such an architecture. Apppcation class-data sharing concept helps in reducing the start up time of an apppcation. Java has an existing CDS (Class-Data Sharing) feature. With Apppcation class-data sharing, Java 10 allows to put apppcation classes in a shared archive. This reduces the apppcation startup and footprint by sharing a common class meta data across multiple java processes.

Process

Apppcation Class data sharing is a 3 step process.

    Create a pst of Classes to archive − Create a pst welcome.lst of a class Greeting.java lying in welcome.jar using Java Launcher.


$java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=welcome.lst -cp welcome.jar Greeting

    Create AppCDS archive − Archive a pst of classes to be used for Apppcation class data sharing.


$java -Xshare:dump -XX:+UseAppCDS -XX:SharedClassListFile=welcome.lst -XX:SharedArchiveFile=welcome.jsa -cp welcome.jar

    Use AppCDS archive − Use AppCDS archive while using java launcher.


$java -Xshare:on -XX:+UseAppCDS -XX:SharedArchiveFile=welcome.jsa -cp welcome.jar Greeting
Advertisements