惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Maciej Walkowiak - Java & Spring

Blog Generating HTTP clients in Spring Boot application from OpenAPI spec PostgreSQL and UUID as primary key Dynamic Projections with Spring Data JPA Container logs with Spring Boot and Testcontainers Reified Generics in Java? Faster integration tests with reusable Testcontainers and Flyway Running one-time jobs with Quartz and Spring Boot The best way to use Testcontainers with Spring Boot Spring Boot & Flyway - clear database between integration tests What's new in Spring? Activate Maven Profile by Operating System Spring Boot with Thymeleaf and Tailwind CSS - Complete Guide How to publish a Java library to Maven Central - Complete Guide Docker Compose - waiting until containers are ready Single file Java applications with JBang Beautiful bash scripts with Gum How to log PostgreSQL queries with Testcontainers Spring Boot 3.0 & GraalVM Native Image - not a free lunch Creating Spring Cloud Function projects with AWS SAM Loading classpath resources to String with a custom JUnit extension Creating Project Templates with Cookiecutter Auto-Registering JUnit 5 extensions Spring Boot component scanning without annotations Listing Maven dependencies in Spring Boot Actuator Info endpoint Spring Cloud AWS 2.3 RC2 Released How I built vlad-cli - command line interface to Vlad Mihalcea The State of Java Relational Persistence On Choosing a Tech Stack
Running Java on CRaC
2022-10-28 · via Maciej Walkowiak - Java & Spring
Published on
  • Java
  • Crac

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!

Requirements ​

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.

How to install ​

  1. Download OpenJDK build from https://github.com/CRaC/openjdk-builds/releases:

bash

$ wget https://github.com/CRaC/openjdk-builds/releases/download/17-crac%2B3/openjdk-17-crac+3_linux-x64.tar.gz
  1. Unpack the archive with sudo (without sudo it's not going to work):

bash

$ sudo tar zxf openjdk-17-crac+3_linux-x64.tar.gz
  1. Set JAVA_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/
  1. Include 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:$PATH

How to run ​

  1. Make sure that you have Maven 3.8.x installed, and it points to CRaC Java version:

bash

$ 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.

  1. Download a Jetty example:

bash

$ git clone https://github.com/CRaC/example-jetty
  1. Build project:
  1. Run JAR with flag -XX:CRaCCheckpointTo=cr:

bash

$ java -XX:CRaCCheckpointTo=cr -jar target/example-jetty-1.0-SNAPSHOT.jar
  1. Open new terminal window, go to the example-jetty and execute:

bash

$ jcmd target/example-jetty-1.0-SNAPSHOT.jar JDK.checkpoint

You should see that cr directory has been created in example-jetty directory.

  1. Now switch back to terminal when Jetty example is running, stop it, and start a project again, this time restoring from the checkpoint:

bash

$ java -XX:CRaCRestoreFrom=cr

Application should start in few milliseconds!

Conclusion ​

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 🍻.

What's next ​

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