Class-Data Sharing


JEP 310 − Application Class-Data Sharing

When JVM is initiated it loads the classes in memory as an introductory step. In case there are many different jars having different classes, an apparent lag shows for the initial request. In serverless architecture, such a lag can postpone the boot time which is a critical operation in such an architecture. Application class-data sharing ideas helps in decreasing the start-up time of an application. Java has a live(present) CDS (Class-Data Sharing) attribute. With Application class-data sharing, Java 10 permits to place application classes in a shared archive. This decreases the application startup and footprint by sharing the same common class metadata around multiple java processes.


The three-step process of Application Class data sharing are given:

  • Create a list of Classes to archive − Make a list welcome.lst of a class Greeting.java lying in welcome.jar by making use of Java Launcher.
$java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=welcome.lst -cp welcome.jar Greeting
  • Create AppCDS archive − Archive a list of classes to be made use of for Application 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 making use of java launcher.
$java -Xshare:on -XX:+UseAppCDS -XX:SharedArchiveFile=welcome.jsa -cp welcome.jar Greeting