Quick revision
The short answer
CRaC (Coordinated Restore at Checkpoint) takes a snapshot of a running, warmed-up JVM, writes it to disk, and later restores new processes from it, so they start in milliseconds and already warm. It is an OpenJDK project that is not in mainline OpenJDK, so we get it from vendor builds such as Azul's or BellSoft's. The application must cooperate: it implements org.crac Resource callbacks to close sockets, files and pools before the checkpoint and reopen them after restore, and it must refresh anything in memory that should not be shared, such as secrets, random seeds and host names. Spring Framework 6.1 does most of this for its own lifecycle and can take the checkpoint automatically after startup.
What to remember
In this answer, we saw that CRaC saves a running, warmed-up JVM to disk and restores copies of it, so new instances skip both startup and warmup. It lives in vendor builds such as Azul's and BellSoft's rather than mainline OpenJDK. Applications cooperate through org.crac Resource callbacks, or Spring's Lifecycle integration from Spring Framework 6.1, closing sockets, files and pools before the checkpoint and reopening them after restore. Because the snapshot holds everything in memory, secrets, random seeds and host-specific values must be refreshed after restore and the files protected.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
CRaC (Coordinated Restore at Checkpoint) takes a snapshot of a running, warmed-up JVM, writes it to disk, and later restores new processes from it, so they start in milliseconds and already warm. It is an OpenJDK project that is not in mainline OpenJDK, so we get it from vendor builds such as Azul's or BellSoft's. The application must cooperate: it implements org.crac Resource callbacks to close sockets, files and pools before the checkpoint and reopen them after restore, and it must refresh anything in memory that should not be shared, such as secrets, random seeds and host names. Spring Framework 6.1 does most of this for its own lifecycle and can take the checkpoint automatically after startup.
Why this question is asked
Java services are slow twice: once at startup, while classes load and beans are created, and again for some minutes afterwards, while the JIT compiles hot code. CRaC tries to remove both at once by reusing a process that has already gone through them. It sounds like magic, and that is why interviewers ask about it: the interesting part is not the speed, but what the application must do so that a copied process behaves correctly. In this answer, we will recap the problem CRaC solves, follow a checkpoint and restore step by step, see where to get it, write a Resource, look at how Spring integrates with it, and finish with what the snapshot remembers that it should not.
1The Problem CRaC Solves
When a Spring Boot service starts, it spends seconds loading classes, reading configuration and creating beans. Then it serves requests, but slowly at first, because the JVM interprets bytecode until the JIT compiler, which turns frequently used methods into optimised machine code, has gathered enough information to compile them. Only after thousands of requests does the service reach its best speed.
All of that work produces the same result on every start. A process that has finished it is, in a sense, a valuable object: its heap holds the created beans and caches, and its code cache holds the compiled methods. CRaC's idea is to save that process to disk once and copy it, instead of rebuilding it each time.
2Checkpoint and Restore Step by Step
A checkpoint freezes the process and writes its memory to a directory. On Linux, CRaC has traditionally used CRIU (Checkpoint/Restore In Userspace), a Linux tool that can dump and restore a process. A restore starts a new process from that directory, and the program continues exactly where it stopped.
8 messages in order. Play them, or step through them one at a time.
The callbacks on each side are what make the copy safe to run.
The word coordinated in the name is the important part. A process cannot be saved safely while it holds open sockets, files or database connections, because those belong to the operating system and the other side, not to the process. So before the checkpoint, the JVM calls back into the application to let it close them, and after restore, it calls back again so the application can reopen them. If something is still open when the checkpoint is taken, the JVM refuses and reports which file or socket was left open.
3Where to Get CRaC
CRaC is an OpenJDK project, but its code is not part of the mainline JDK that most distributions build, so a regular Temurin or Oracle JDK does not have it. It is available in some vendor builds, for example Azul Zulu builds with CRaC and BellSoft Liberica builds with CRaC, on Linux. Some vendors have also added checkpoint engines that need fewer operating-system privileges than CRIU; check your vendor's documentation for what your build supports.
The application code itself does not depend on a vendor. It uses the small org.crac library, which offers the same interfaces on every JDK. On a JDK without CRaC the library does nothing, so the same jar runs on a normal JDK too, just without checkpoints.
4Writing a Resource
An application object that holds an outside resource implements org.crac.Resource and registers itself with the global context. Here is a client that keeps a socket open to a price feed.
Notice that the two callbacks are mirror images. Whatever beforeCheckpoint() closes, afterRestore() must reopen, and code that runs between them must not use the resource. The same applies to pools, file handles and message consumers.
5How Spring Integrates With CRaC
Writing callbacks for every pool in a Spring application would be a lot of work, so Spring Framework 6.1 integrates CRaC with its own lifecycle. Beans that implement Spring's Lifecycle interface are stopped before a checkpoint and started again after restore, and Spring Boot 3.2 and later uses this for the web server, connection pools and other managed components it supports. Our own beans can implement Lifecycle, which is often simpler than implementing Resource directly.
Spring can also take the checkpoint for us. Starting the application with -Dspring.context.checkpoint=onRefresh makes Spring create the checkpoint automatically during startup, after the singletons are created but before the lifecycle beans are started, so no connections are open yet. That gives fast startup, although the JIT has not warmed up much at that point. For a warm snapshot we start the application, send it representative traffic, and trigger the checkpoint with jcmd.
6What the Snapshot Remembers
Everything in memory goes into the snapshot. That includes values we do not want copied. A database password or an OAuth token read at startup is now in a file on disk, and in every restored instance. A random number generator seeded before the checkpoint produces the same sequence in every copy, which matters for anything security related. A cached host name or instance id is wrong in every copy except the first. Time also jumps: the restored process may think it is still the moment of the checkpoint until it reads the clock again.
So a correct CRaC application refreshes these in afterRestore(): it rereads credentials or fetches fresh tokens, reseeds random generators that matter, recomputes host-specific values and clears caches that depend on time. The snapshot files themselves must be protected like secrets, with restricted permissions and encryption at rest, because anyone who reads them can read the heap.
7Follow-up questions
Is CRaC the same as the JDK AOT cache?
No. The AOT cache, from JEP 483, stores loaded and linked classes and method profiles, and every start still runs the application's startup code. CRaC stores the whole running process, including the heap and compiled code, and skips startup entirely. CRaC is faster, but it needs vendor builds, operating-system support and application cooperation, while the AOT cache is in mainline OpenJDK and needs none of that.
What happens if a resource is left open at checkpoint time?
The checkpoint fails with an exception that names the open file or socket, and the application keeps running. That is a safety feature: a snapshot with a half-open connection could not be restored correctly, so the JVM refuses to write it.
Can we checkpoint once and restore on any machine?
Only within limits. The restored process expects a compatible kernel, CPU features and file paths, and the same JDK build. In practice, teams create the snapshot in the same image that runs it and restore it on similar nodes. Check your vendor's documentation for the exact compatibility rules.
8Conclusion
In this answer, we saw that CRaC saves a running, warmed-up JVM to disk and restores copies of it, so new instances skip both startup and warmup. It lives in vendor builds such as Azul's and BellSoft's rather than mainline OpenJDK. Applications cooperate through org.crac Resource callbacks, or Spring's Lifecycle integration from Spring Framework 6.1, closing sockets, files and pools before the checkpoint and reopening them after restore. Because the snapshot holds everything in memory, secrets, random seeds and host-specific values must be refreshed after restore and the files protected.
Open with
CRaC, Coordinated Restore at Checkpoint, lets us take a snapshot of a running JVM, after startup and ideally after warmup, write it to disk, and start new processes by restoring that snapshot.
Then, if they want more
A restored instance is ready in tens of milliseconds and the JIT-compiled code is already there. It is an OpenJDK project but not in mainline OpenJDK, so in practice it comes from vendor builds like Azul Zulu or BellSoft Liberica on Linux.
The coordinated part is the application's job: open sockets, files and connection pools cannot be saved, so objects that hold them implement org.crac Resource, closing them in beforeCheckpoint and reopening them in afterRestore. If something is left open, the checkpoint fails.
In Spring Framework 6.1 and Spring Boot 3.2, Spring stops Lifecycle beans before the checkpoint and restarts them after restore, and with spring.context.checkpoint=onRefresh it can take the checkpoint automatically during startup. The thing I would be most careful about is that everything in memory is in the snapshot: credentials, tokens, random seeds, host names and cached time.
Those need to be refreshed after restore, and the snapshot files need to be protected like secrets.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6, Spring Boot 3.2
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is CRaC (Coordinated Restore at Checkpoint), and what must an application do to...": https://scrivio-interview-library.netlify.app/java/startup-and-footprint/f075cc198a/