Skip to content

Commit 862611a

Browse files
snicollscottfrederick
authored andcommitted
Refine Efficient Deployments section in the reference guide
See gh-40175
1 parent 70a992d commit 862611a

File tree

1 file changed

+31
-5
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/deployment

1 file changed

+31
-5
lines changed

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/deployment/efficient.adoc

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
[[deployment.efficient.unpacking]]
77
== Unpacking the Executable JAR
88

9-
If you are running your application, you can use an executable jar, but it is also often an advantage to extract it and run it in a different way.
9+
You can run your application using the executable jar, but loading the classes from nested jars has a small cost.
10+
Depending on the size of the jar, running the application from an exploded structure is faster and recommended in production.
1011
Certain PaaS implementations may also choose to extract archives before they run.
1112
For example, Cloud Foundry operates this way.
1213

13-
With the help of the jarmode, you can extract the jar to different layouts.
14-
The most efficient layout is a CDS (class data sharing) friendly layout.
15-
This layout is used by default.
14+
Spring Boot supports extracting your application to a directory using different layouts.
15+
The default layout is the most efficient, and is xref:#deployment.efficient.cds[CDS friendly].
1616

1717
In this layout, the libraries are extracted to a `lib/` folder, and the application JAR
1818
contains the application classes and a manifest which references the libraries in the `lib/` folder.
@@ -23,19 +23,45 @@ $ java -Djarmode=tools -jar my-app.jar extract
2323
$ java -jar my-app/my-app.jar
2424
----
2525

26-
This is actually faster on startup (depending on the size of the jar) than running from an unexploded archive.
2726
After startup, you should not expect any differences.
2827

2928
TIP: Run `java -Djarmode=tools -jar my-app.jar help extract` to see all possible options.
3029

3130

31+
[[deployment.efficient.cds]]
32+
== Optimize Startup Time with CDS
33+
34+
Class Data Sharing (CDS) is a https://docs.oracle.com/en/java/javase/17/vm/class-data-sharing.html[JVM feature] that can help reduce the startup time and memory footprint of Java applications.
35+
36+
To use it, you should first perform a training run on your application in exploded form:
37+
38+
[source,shell]
39+
----
40+
$ java -Djarmode=tools -jar my-app.jar extract --destination application
41+
$ cd application
42+
$ java -XX:ArchiveClassesAtExit=application.jsa -Dspring.context.exit=onRefresh -jar my-app.jar
43+
----
44+
45+
This creates an `application.jsa` file that can be reused as long as the application is not updated.
46+
47+
To use the cache, you need to add an extra parameter when starting the application:
48+
49+
[source,shell]
50+
----
51+
$ java -XX:SharedArchiveFile=application.jsa -jar my-app.jar
52+
----
53+
54+
NOTE: For more details about CDS, refer to the {url-spring-framework-docs}/integration/cds.html[Spring Framework reference documentation]
55+
3256

3357
[[deployment.efficient.aot]]
3458
== Using Ahead-of-time Processing With the JVM
3559

3660
It's beneficial for the startup time to run your application using the AOT generated initialization code.
3761
First, you need to ensure that the jar you are building includes AOT generated code.
3862

63+
NOTE: CDS and AOT can be combined to further improve startup time.
64+
3965
For Maven, this means that you should build with `-Pnative` to activate the `native` profile:
4066

4167
[source,shell]

0 commit comments

Comments
 (0)