Visit Azul.com Support

Frameworks With CRaC Support

CRaC can be added to any Java application thanks to the org.crac:crac library, as described on Coordinated Restore at Checkpoint Usage Guidelines. But several frameworks also integrated CRaC and provide the functionality out-of-the-box.

Spring and Spring Boot

As of Spring 6.1 and SpringBoot 3.2, both frameworks come with full support for CRaC. This can be used in two ways. And example Spring Boot CRaC project is available on github.com/CRaC/example-spring-boot.

Automatic Checkpoint

The engineers in the Spring team had a nice idea to improve the startup time of the Spring/SpringBoot framework by creating a checkpoint automatically right before the application is started, as described in the Spring documentation:

"When the -Dspring.context.checkpoint=onRefresh JVM system property is set, a checkpoint is created automatically at startup during the LifecycleProcessor.onRefresh phase. After this phase has completed, all non-lazy initialized singletons have been instantiated, and InitializingBean#afterPropertiesSet callbacks have been invoked; but the lifecycle has not started, and the ContextRefreshedEvent has not yet been published."

Start the application as follows to use the automatic checkpointing:

 
java -Dspring.context.checkpoint=onRefresh \ -XX:CRaCCheckpointTo=./my_checkpoint -jar MY_APP.jar

After executing the application, a checkpoint is created, the checkpoint files are stored in the folder ./my_checkpoint, and the application exits. Now you can restore the application from the checkpoint (which means starting it again) by executing:

 
java -XX:CRaCRestoreFrom=./my_checkpoint

Manual Checkpoint

In most cases, you can get better startup times with a manual checkpoint, which is created further in the live time of an application, when it is completely warmed up and most of the code is compiled and optimized. Such a manual checkpoint needs to be triggered from outside the application, instead of having the framework creating the checkpoint automatically. A manual triggered checkpoint does not only contain the framework code but also the application code which means you will see an even faster startup because the application was already loaded and started by the framework.

Before we start, make sure that the folder for the checkpoint is empty, and start the application as follows:

 
java -XX:CRaCCheckpointTo=./my_checkpoint -jar MY_APP.jar

Wait till the application is completely started up, and open a second shell window. Execute the following command:

 
jcmd spring-petclinic-3.2.0.jar JDK.checkpoint

In the first shell window, where you started the application, a checkpoint is created and the application will shut down. Now you can close the second shell window. To restore the application from this checkpoint, execute the same command as for the automatic checkpoint:

Start the application as follows to use the automatic checkpointing:

 
java -XX:CRaCRestoreFrom=./my_checkpoint

Startup time improvements with Spring and CRaC

In tests with the SpringBoot PetClinic example application, the following results were measured:

Azul Zulu Version Method Result

JDK 17

Normal startup

4632 ms

JDK 21

Normal startup

4099 ms

JDK 21

Automatic Checkpoint

392 ms

JDK 21

Manual Checkpoint

75 ms

More info is available in this blog post by Gerrit Grunwald.

Micronaut

To use CRaC in a Micronaut project, you need to add the following dependency:

 
implementation("io.micronaut.crac:micronaut-crac")

An example Micronaut CRaC project is available on github.com/CRaC/example-micronaut. The Micronaut CRaC documentation can be found here.

Creating a Checkpoint with Micronaut

Start the application in the checkpoint mode:

 
java -XX:CRaCCheckpointTo=./my_checkpoint -jar MY_APP.jar

Warm-up the instance, for instance with:

 
siege -c 1 -r 100000 -b http://localhost:8080/hello/test

In a second terminal, request a checkpoint:

 
jcmd build/libs/MY_APP.jar JDK.checkpoint

Restoring from the Checkpoint

 
java -XX:CRaCRestoreFrom=./my_checkpoint

Quarkus

An example Quarkus CRaC project is available on github.com/CRaC/example-quarkus. The checkpoint creating and restore is similar as for other frameworks.

Creating a Checkpoint with Quarkus

Start the application in the checkpoint mode:

 
java -XX:CRaCCheckpointTo=./my_checkpoint -jar MY_APP.jar

Warm-up the instance, for instance with:

 
siege -c 1 -r 100000 -b http://localhost:8080/hello/test

In a second terminal, request a checkpoint:

 
jcmd build/libs/MY_APP.jar JDK.checkpoint

Restoring from the Checkpoint

 
java -XX:CRaCRestoreFrom=./my_checkpoint