Which application classes to archive

The next step in creating a shared archive includes specifying the application classes to be included. Examine the myCDSlog.log file that you created in the preceding section. It doesn't include each class or interface that is defined in the core Java API.

Similarly, even though your application might include a lot of classes, you need not include all of them in the shared archive file, simply because not all of them are required at startup. This also reduces the size of the shared archive file.

Here's an example to find the application classes that should be added to the shared archive. To start with, create a jar file of your application files.

Let's create four skeleton class files in the com.ejavaguru.appcds package:

// Contents of Cotton.java 
package com.ejavaguru.appcds; 
public class Cotton {} 
 
// Contents of Plastic.java 
package com.ejavaguru.appcds; 
public class Plastic {} 
 
// Contents of PlasticBottle.java 
package com.ejavaguru.appcds; 
public class PlasticBottle extends Plastic {}  
 
// Contents of Wood.java 
package com.ejavaguru.appcds; 
public class Wood {}

And here's the content of the AppCDS class, which uses one of the preceding classes. It isn't defined in the same package:

// Contents of class AppCDS.java 
import com.ejavaguru.appcds.*; 
class AppCDS { 
    public static void main(String args[]) { 
        System.out.println(new Plastic()); 
    } 
} 

If your directory structure matches your package structure, you can create a jar file using the following command:

To determine the application classes that should be placed in the shared archive, execute the following command:

java -Xshare:off  
     -XX:DumpLoadedClassList=myappCDS.lst 
     -cp appcds.jar 
      AppCDS 

On execution of the previous command, myappCDS.lst records the fully qualified name (separated using ) of all classes (approximately 500) that were loaded by JVM. It includes both the core API classes and your application classes.

The following screenshot includes a few of these class names from the myappCDS.lst file. I've highlighted the names of two application files included in this list—AppCDS and com/ejavaguru/appcds/Plastic:

If you revisit the code of the AppCDS class, you'll notice that it uses just one class, that is, Plastic, from the com.ejavaguru.appcds package. The other classes from the same package are not loaded because they are not used. If you want to load other specific classes, you should use them in your application.

After accessing the list of application files to be included in the shared archive, you can move forward and create it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.107.254