Using CRaC with SpringBoot 3.2: A Practical Guide and Performance Evaluation

This article explains how to enable and use the OpenJDK CRaC project with SpringBoot 3.2, covering prerequisites, dependency setup, automatic and manual checkpoint creation, and demonstrates significant startup‑time reductions through detailed examples and performance results.

Architecture Digest
Architecture Digest
Architecture Digest
Using CRaC with SpringBoot 3.2: A Practical Guide and Performance Evaluation

Spring 6.1 and SpringBoot 3.2 fully support CRaC, an OpenJDK project that can snapshot a running JVM (including the application state) to disk and later restore it in milliseconds, dramatically speeding up application startup.

Prerequisites for using CRaC with SpringBoot 3.2 are a CRaC‑enabled JVM (e.g., Azul Zulu 21.0.1 + CRaC), the org.crac library, and a writable folder for storing checkpoints. On Linux you may need to adjust permissions for the CRIU binaries:

sudo chown root:root $JAVA_HOME/lib/criu
sudo chmod u+s $JAVA_HOME/lib/criu

Add the org.crac dependency to your build: implementation 'org.crac:crac:1.4.0' or, for Maven:

<dependency>
  <groupId>org.crac</groupId>
  <artifactId>crac</artifactId>
  <version>1.4.0</version>
</dependency>

Create a folder (e.g., /tmp_checkpoint) in the project directory to hold checkpoint files.

Running without CRaC : after cloning the Spring‑Petclinic repository, build it with ./gradlew clean build and start the jar with java -jar spring-petclinic-3.2.0.jar. Switching from JDK 17 to JDK 21 already reduces startup time by about 500 ms.

Automatic checkpoint : start the application with the JVM flag -Dspring.context.checkpoint=onRefresh and specify the checkpoint directory:

java -Dspring.context.checkpoint=onRefresh -XX:CRaCCheckpointTo=./tmp_checkpoint -jar spring-petclinic-3.2.0.jar

The framework creates a checkpoint during the onRefresh phase; restoring it later with java -XX:CRaCRestoreFrom=./tmp_checkpoint cuts the startup time by an order of magnitude without any code changes.

Manual checkpoint : start the app with -XX:CRaCCheckpointTo=./tmp_checkpoint, let it fully start, then in a second shell trigger a checkpoint: jcmd spring-petclinic-3.2.0.jar JDK.checkpoint After the checkpoint is created, restore the application using the same -XX:CRaCRestoreFrom flag, achieving a startup time of roughly 75 ms—two orders of magnitude faster than a cold start.

Because Spring 6.1/Boot 3.2 handle resource shutdown and restoration automatically, no code modifications are required for the automatic checkpoint path; manual checkpoints may need additional resource‑handling code.

Overall, CRaC can dramatically reduce SpringBoot startup latency: the automatic checkpoint provides a ten‑fold improvement, while a manually triggered checkpoint can bring startup down to tens of milliseconds.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendjavaperformanceSpringBootCheckpointCRaC
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.