How to Supercharge Spring Boot 3.2 Startup with CRaC Checkpointing
This guide explains how Spring Boot 3.2 leverages the OpenJDK CRaC project to create and restore JVM checkpoints, dramatically reducing application startup time through automatic and manual checkpoint techniques, complete with required dependencies, installation steps, and performance results.
Introduction
Spring 6.1 and Spring Boot 3.2 fully support CRaC (Coordinated Restore at Checkpoint), an OpenJDK project that can snapshot a running JVM—including the application state—to disk and later restore it almost instantly.
Prerequisites
A CRaC‑compatible JVM (e.g., Azul Zulu 21.0.1+ CRaC)
The org.crac JAR dependency
A writable directory for checkpoint files
Installation
Install Azul Zulu 21.0.1+ CRaC from Azul . On Linux, grant the necessary permissions for CRIU:
sudo chown root:root $JAVA_HOME/lib/criu
sudo chmod u+s $JAVA_HOME/lib/criuAdd the CRaC dependency to your project:
<dependency>
<groupId>org.crac</groupId>
<artifactId>crac</artifactId>
<version>1.4.0</version>
</dependency>Baseline Test
Running the Spring Boot Petclinic demo on JDK 17 vs. JDK 21 reduces startup time by about 500 ms. Launch the application with: java -jar spring-petclinic-3.2.0.jar The baseline startup takes roughly 4 seconds.
Automatic Checkpoint
Enable automatic checkpointing by setting the JVM system property -Dspring.context.checkpoint=onRefresh. The checkpoint is created after the LifecycleProcessor.onRefresh phase, before the ContextRefreshedEvent is published.
java -Dspring.context.checkpoint=onRefresh -XX:CRaCCheckpointTo=./tmp_checkpoint -jar spring-petclinic-3.2.0.jarAfter the application exits, the checkpoint files reside in ./tmp_checkpoint. Restore the application with: java -XX:CRaCRestoreFrom=./tmp_checkpoint Restored startup time improves by an order of magnitude.
Manual Checkpoint
For even faster restarts, create a checkpoint manually after the application is fully warmed up:
java -XX:CRaCCheckpointTo=./tmp_checkpoint -jar spring-petclinic-3.2.0.jarIn a second shell, trigger the checkpoint: jcmd spring-petclinic-3.2.0.jar JDK.checkpoint Verify the checkpoint files in ./tmp_checkpoint, then restore with the same -XX:CRaCRestoreFrom command. Manual checkpoints include both framework and application code, yielding the fastest startup.
Special Notes
Spring Boot 3.2 requires no code changes to use CRaC; the framework handles resource shutdown before the checkpoint and reopens them after restore. For other frameworks, implement the CRaC Resource interface and manage resources in beforeCheckpoint() and afterRestore().
Conclusion
Using CRaC with Spring Boot 3.2 can reduce startup time by an order of magnitude without modifying application code, offering a simpler alternative to GraalVM Native Image while still benefiting from JVM‑level optimizations.
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 High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
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.
