Quick revision
The short answer
A training run is a run of the application whose purpose is to record what the JVM does during startup: which classes are loaded and linked and, in JDK 25, which methods get hot and how they behave. The recording becomes the AOT cache that later production starts use. Because only work seen during training is cached, the run should cover normal startup and the common paths, and because it is a real run of the application, it must avoid side effects such as writing to production databases or sending messages.
What to remember
In this answer, we saw that a training run starts the application under observation so the JVM can record which classes are loaded and linked and, in JDK 25, which methods are hot, and that the recording becomes the AOT cache used by later starts. Since only work seen during training is cached, the run should cover normal startup and the common request paths with representative traffic. And because a training run really executes the application, it needs its own profile and environment so it never writes to production databases, consumes real messages or calls real external systems.
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.
A training run is a run of the application whose purpose is to record what the JVM does during startup: which classes are loaded and linked and, in JDK 25, which methods get hot and how they behave. The recording becomes the AOT cache that later production starts use. Because only work seen during training is cached, the run should cover normal startup and the common paths, and because it is a real run of the application, it must avoid side effects such as writing to production databases or sending messages.
Why this question is asked
The AOT cache from Project Leyden is the most significant startup feature the JVM has gained in years, and using it well depends almost entirely on one step: the training run. A good training run gives fast startup and quick warmup; a poor one gives a cache that helps little, and a careless one can cause real damage by touching production systems. Interviewers ask about it to see whether we understand that the cache is a recording of behaviour, not a compiler output. In this answer, we will recap what the AOT cache is, walk through a training run step by step, see why what the run does decides the benefit, and look at how to make training runs safe.
1A Quick Recap of the AOT Cache
Every time a JVM starts, it repeats the same work: it finds, parses, verifies and links thousands of classes, and then it interprets code, gathers profiles and compiles hot methods. Class Data Sharing has long saved part of the first step by storing parsed class metadata in an archive. The AOT cache, introduced in JDK 24 by JEP 483, goes further. It stores classes in an already loaded and linked state, so production starts can skip even more work.
JDK 25 extended the cache with method profiles (JEP 515), information about which methods ran often and how, so the JIT can compile hot code sooner after startup, and made creating the cache easier (JEP 514). The key idea is the same throughout: the JVM watches a real run of the application, writes down what happened, and reuses that recording.
2What a Training Run Is
A training run is simply the application started with options that tell the JVM to observe and record. It does its normal startup, and ideally some typical work, and when it exits, the JVM writes the recording. In JDK 25 the simplest form is a single option.
6 messages in order. Play them, or step through them one at a time.
Production starts reuse what the training run observed.
In the two-step form we can see the separation clearly: the record step runs the application and saves a configuration describing what it observed, and the create step builds the cache from that configuration without running the application. The one-step option does both. Production starts then map the cache. Like CDS archives, the cache is valid only with the same JDK build and a compatible class path, and the JVM ignores it otherwise unless we demand it.
3Why What the Training Run Does Matters
The cache can only contain what the training run actually did. If a class was never loaded during training, it is not in the cache, and production loads it the normal way. If a method never ran during training, there is no profile for it, and the JIT has to learn about it from scratch in production.
So the content of the run decides the benefit. A run that only starts the application and exits gives faster startup, because the startup classes are cached, but little help with warmup. A run that also exercises the common request paths, such as the main API endpoints, serialisation, database access and the frameworks' first-request initialisation, caches those classes too and records profiles for the methods that will be hot in production, so the service reaches good performance sooner after it starts taking traffic.
| Training run does | Cached | Effect in production |
|---|---|---|
| Start and exit immediately | startup classes | faster startup, normal warmup |
| Start plus common requests | startup and request-path classes, hot profiles | faster startup and faster warmup |
| Start plus rare edge cases only | classes of unusual paths | little benefit, misleading profiles |
There is a balance. The training workload should resemble normal production traffic, not unusual edge cases, because profiles from unrepresentative work can lead the JIT to optimise for the wrong things. And the training run should be short and repeatable, because it becomes part of every build.
4Keeping the Training Run Safe
Here is the part that is easy to forget: a training run is a real execution of the application. Whatever the code does at startup and on the requests we send, it really does. If the training run starts with production configuration, it may run database migrations against production, consume and acknowledge messages from a real queue, send emails or webhooks, call payment providers, or write to shared caches.
So the training run needs its own environment and configuration. A training profile points the application at a disposable database, such as a container started just for the build, with the schema and a little test data. Outgoing integrations are pointed at stubs or disabled, message listeners connect to a local broker or are switched off, and scheduled jobs do not start. Credentials for production systems are simply not available in the build environment, which is the strongest guarantee.
Notice that the training profile changes where the application connects, not which code runs. We want the same classes to load and the same paths to execute as in production; we just do not want their effects to reach real systems. The JVM writes the cache when the application exits normally, so the script stops it with a regular termination signal.
5Follow-up questions
Is the training run the same as a CDS training run?
It follows the same idea and the same rules, a run that records behaviour on the exact production JDK, but the AOT cache records more: linked classes and, in JDK 25, method profiles. Spring's -Dspring.context.exit=onRefresh option gives a quick startup-only training run for either.
Does the AOT cache contain compiled machine code?
In JDK 24 and 25, it stores loaded and linked classes and, in 25, method profiles, which help the JIT compile earlier. Storing compiled code itself is further work planned in Project Leyden, so check the status for your JDK version.
How do you know the cache was used in production?
Start with -Xlog:aot or -Xlog:cds to see whether the cache was mapped (check the log tags for your version), and compare startup time and time to good latency with and without the cache. Using -XX:AOTMode=on makes the JVM fail at startup if the cache cannot be used, which is useful in tests.
6Conclusion
In this answer, we saw that a training run starts the application under observation so the JVM can record which classes are loaded and linked and, in JDK 25, which methods are hot, and that the recording becomes the AOT cache used by later starts. Since only work seen during training is cached, the run should cover normal startup and the common request paths with representative traffic. And because a training run really executes the application, it needs its own profile and environment so it never writes to production databases, consumes real messages or calls real external systems.
Open with
A training run is a run of the application whose job is to show the JVM what a typical startup looks like. In JDK 25 I start the app with -XX:AOTCacheOutput, or in the JDK 24 style with AOTMode record and then create, and while it runs the JVM records which classes get loaded and linked and, since JDK 25, method profiles for the code that gets hot.
Then, if they want more
When it exits, that recording becomes the AOT cache, and production starts with -XX:AOTCache use it to skip the class loading and linking work and to let the JIT compile hot methods sooner. What the training run does matters because only what it saw gets cached.
If it just starts and exits, I get faster startup but little help with warmup. If it also sends a few typical requests through the main endpoints, those classes and profiles are included and the service warms up faster. It should be representative, not edge cases.
And because it is a real execution, it must be safe: a dedicated training profile with a throwaway database, a local or disabled message broker, stubbed external calls and no production credentials, so it never runs migrations against production or sends real messages. The cache also has to be created with the same JDK build and class path as production.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25, Java 24
- 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 a training run in the context of the JDK AOT cache, and why does it matter what...": https://scrivio-interview-library.netlify.app/java/startup-and-footprint/5611924be7/