Accelerate Spring Boot 3.2 Startup with CRaC: Automatic & Manual Checkpoints
This article demonstrates how Spring Boot 3.2 leverages the OpenJDK CRaC project to dramatically cut application startup time, covering required JVM, dependencies, Zulu JDK setup, automatic and manual checkpoint creation, performance benchmarks, and restoration steps, all using the Petclinic example.
1. Introduction
Spring 6.1 and Spring Boot 3.2 have been released and both fully support CRaC (Coordinated Restore at Checkpoint).
CRaC, an OpenJDK project, can snapshot a running JVM (including the application) to disk and later restore it, enabling millisecond‑level startup by reusing a pre‑warmed state.
To test Spring Boot 3.2’s CRaC support, the Spring Boot Petclinic sample is used.
2. Dependencies
Using CRaC in Spring Boot 3.2 requires three conditions:
CRaC‑compatible JVM
org.crac JAR dependency
A folder to store checkpoint files
2.1 Install Zulu JDK
The required JDK is Azul Zulu 21.0.1 + CRaC . Download from Azul . CRaC is currently only available on Linux.
Set permissions for CRIU on Linux:
sudo chown root:root $JAVA_HOME/lib/criu
sudo chmod u+s $JAVA_HOME/lib/criu2.2 Add JAR dependency
Clone the Petclinic source and add the org.crac:crac:1.4.0 dependency in Maven:
<dependency>
<groupId>org.crac</groupId>
<artifactId>crac</artifactId>
<version>1.4.0</version>
</dependency>3. Baseline Test
Testing on JDK 17 and JDK 21 shows that simply moving to JDK 21 reduces Petclinic startup time by about 500 ms.
Run the application: java -jar spring-petclinic-3.2.0.jar Startup time statistics:
3.1 Automatic Checkpoint with CRaC
Enable automatic checkpoint by adding the JVM system property -Dspring.context.checkpoint=onRefresh. During the LifecycleProcessor.onRefresh phase, a checkpoint is created after all non‑lazy singletons are instantiated but before the ContextRefreshedEvent is published.
java -Dspring.context.checkpoint=onRefresh -XX:CRaCCheckpointTo=./tmp_checkpoint -jar spring-petclinic-3.2.0.jarThe application creates a checkpoint in ./tmp_checkpoint and exits.
Restore from the checkpoint: java -XX:CRaCRestoreFrom=./tmp_checkpoint Resulting startup time (from checkpoint) is an order of magnitude faster:
3.2 Manual Checkpoint
Manual checkpoints can be created at any desired moment, offering even faster restarts.
Steps:
Start the application without checkpointing:
java -XX:CRaCCheckpointTo=./tmp_checkpoint -jar spring-petclinic-3.2.0.jarWhen the app is fully started, trigger a checkpoint from another shell: jcmd spring-petclinic-3.2.0.jar JDK.checkpoint A checkpoint file appears in ./tmp_checkpoint and the app shuts down.
Restore the same way as the automatic case: java -XX:CRaCRestoreFrom=./tmp_checkpoint This manual checkpoint includes both framework and application code, yielding even quicker startups:
4. Special Notes
Spring Boot 3.2 fully supports CRaC without any code changes; the framework handles resource closing before the checkpoint and reopening after restore.
For other frameworks you must implement the CRaC Resource interface, closing resources in beforeCheckpoint() and reopening them in afterRestore().
5. Conclusion
Using CRaC can dramatically reduce Spring Boot 3.2 application startup time, often by an order of magnitude, without modifying source code. Automatic checkpoints provide a simple way to achieve this, while manual checkpoints can deliver even faster restarts. Compared with GraalVM Native Image, CRaC runs on a standard JVM and allows further optimizations after restoration.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
