


























Have you heard about CRaC? It's an experimental project lead by Azul that researches a mechanism to checkpoint (make an image of, snapshot) a Java instance while it is executing and then restore from this snapshot.
Potentially it could solve typical JVM problems with slow startup & warm up times. Sounds familiar? Yes, there are quite a few initiatives in the Java world that address the very same problem.
I recommend learning more about CraC here:
CRaC is not yet build into any official JDK and you won't find it in SDKMan.
It took me some time to figure out how to even run examples, so here's a step by step guide on how to set up a development machine to play with CRaC distribution of OpenJDK.
Big thanks to Sergio del Amo for hints!
There is no CRaC distribution for MacOS or Windows. I failed to get it running both as Docker container or on Gitpod (probably because it also runs on Docker).
To run CRaC you have to use Linux, or create a virtual machine for example with VirtualBox.
Also note - CRaC does not work on Ubuntu 22. I've managed to get it running on Ubuntu 18.04.
bash
$ wget https://github.com/CRaC/openjdk-builds/releases/download/17-crac%2B3/openjdk-17-crac+3_linux-x64.tar.gzbash
$ sudo tar zxf openjdk-17-crac+3_linux-x64.tar.gzJAVA_HOME to point to the OpenJDK CRaC directory:For example, assuming that the JDK is located in /opt/:
bash
$ export JAVA_HOME=/opt/openjdk-17-crac+3_linux-x64/bin directory in PATH. Important: make sure that it's added before current path:bash
export PATH=/opt/openjdk-17-crac+3_linux-x64/bin:$PATHbash
$ mvn --version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /home/maciej/Downloads/maven/apache-maven-3.8.6
Java version: 17-crac, vendor: N/A, runtime: /home/maciej/Downloads/openjdk-17-crac+3_linux-x64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-84-generic", arch: "amd64", family: "unix"If you are on Ubuntu 18.04 and run apt-get install maven, you will get Maven 3.6 installed that is not compatible with Java 17. In such case, download Maven manually from https://maven.apache.org/download.cgi.
bash
$ git clone https://github.com/CRaC/example-jetty-XX:CRaCCheckpointTo=cr:bash
$ java -XX:CRaCCheckpointTo=cr -jar target/example-jetty-1.0-SNAPSHOT.jarexample-jetty and execute:bash
$ jcmd target/example-jetty-1.0-SNAPSHOT.jar JDK.checkpointYou should see that cr directory has been created in example-jetty directory.
bash
$ java -XX:CRaCRestoreFrom=crApplication should start in few milliseconds!
Does it mean that you can just take any application, create a snapshot and have it start in milliseconds? Not really. To make an application CRaC friendly, there must be no open sockets so application frameworks and underlying servlet containers like Tomcat, would have to ba adjusted to get it working.
There is a sample available for Spring Boot, but it's based on Boot 2.0.5, which isn't compatible with Java 17, which means to run it you would have to use old OpenJDK CRaC build - and you would have to build it yourself.
Micronaut is the only mainstream framework with the official support for CRaC: Micronaut CRaC. Kudos to Tim Yates and Sergio del Amo 🍻.
I recommend looking into following guides to continue experimenting with CRaC:
Let's stay in touch and follow me on Twitter: @maciejwalkowiak
Subscribe to RSS feed ![]()
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。