<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl" -->

---
title: A Guide to Ahead-of-Time Cache in the Java | daily.dev
description: Java's Ahead-of-Time (AOT) cache, introduced in JDK 24 via JEP 483 and enhanced in JDK 25 and 26, lets the JVM save class-loading and linking work to disk so...
canonical: https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: A Guide to Ahead-of-Time Cache in the Java | daily.dev
og:description: Java's Ahead-of-Time (AOT) cache, introduced in JDK 24 via JEP 483 and enhanced in JDK 25 and 26, lets the JVM save class-loading and linking work to disk so...
og:url: https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl
og:image: https://api.daily.dev/og/posts/xFPtXKmvL.png
og:image:alt: A Guide to Ahead-of-Time Cache in the Java
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# A Guide to Ahead-of-Time Cache in the Java

**[Baeldung](https://daily.dev/sources/baeldung)** · 9 min read · 3 upvotes · 0 comments

## Summary

Java's Ahead-of-Time (AOT) cache, introduced in JDK 24 via JEP 483 and enhanced in JDK 25 and 26, lets the JVM save class-loading and linking work to disk so subsequent app startups are faster. The tutorial walks through the three-phase workflow (record, create, run), a simplified one-step approach using -XX:AOTCacheOutput, and memory considerations for small machines. It also covers how to keep training and production runs aligned, validate cache integrity with -XX:AOTMode=on, and use JDK Flight Recorder to identify hot methods missing from training. A lightweight smoke test is recommended to drive training runs without pulling in heavy test suites.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://feeds.feedblitz.com/~/964742378/0/baeldung>

## Questions this post answers

### How do I build a Java AOT cache in a single step instead of the three-phase workflow?

Pass a destination path to the -XX:AOTCacheOutput flag when running the app normally, for example java -XX:AOTCacheOutput=app.aot -cp app.jar com.example.App, and the JVM builds and writes the cache automatically on shutdown. JEP 514 also offers a two-step variant that records the cache once and reuses it in later runs via -XX:AOTCache=app.aot, without needing the older record/create/run split.

_Developers tuning JVM startup times can track AOT caching techniques like this on daily.dev._

### Why would I use the three-phase AOT cache workflow instead of the simpler one-step command in Java?

The one-step -XX:AOTCacheOutput approach spins up a second heap the same size as the training heap while assembling the cache, roughly doubling peak memory demand, for example needing about 4 GB with -Xms2g -Xmx2g settings. The three-phase record, create, and run workflow lets you record on a modest instance and assemble the cache on a larger one, which matters for small cloud servers with limited memory.

_Teams sizing cloud instances for Java deployments can weigh trade-offs like this via daily.dev._

### What conditions invalidate a Java AOT cache and force a rebuild?

A Java AOT cache is valid for a single build only, so a code change, a new or updated library, or a JDK upgrade each invalidates it, requiring regeneration alongside every build. Training and production runs must also stay aligned: same JAR timestamps, same JDK, hardware, and OS, plain JARs with no folders or wildcards on the classpath, and no JVMTI agents altering class loading at runtime.

_Developers maintaining Java build and deployment pipelines can keep tabs on caching pitfalls via daily.dev._

## Similar posts on daily.dev

- [Run Into the New Year with Java’s Ahead-of-Time Cache Optimizations – Inside.java](https://daily.dev/posts/run-into-the-new-year-with-java-s-ahead-of-time-cache-optimizations-inside-java-75zsl41gf) · Inside Java · 1 upvotes · 0 comments
- [Ahead-of-Time Class Loading & Linking](https://daily.dev/posts/ahead-of-time-class-loading-linking-yftlbv7es) · Baeldung · 0 upvotes · 0 comments
- [JEP 544: Ahead-of-Time Code Compilation](https://daily.dev/posts/jep-544-ahead-of-time-code-compilation-idncwszkw) · Awesome Java Newsletter · 0 upvotes · 0 comments
- [How is Leyden improving Java Performance? Part 2 of](https://daily.dev/posts/how-is-leyden-improving-java-performance-part-2-of-k95xs5i7z) · Foojay.io · 1 upvotes · 0 comments

---

Tags: [#java](https://daily.dev/tags/java), [#jvm](https://daily.dev/tags/jvm)

[View this post on daily.dev](https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"A Guide to Ahead-of-Time Cache in the Java","url":"https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl"},"datePublished":"2026-07-30T23:28:59.719Z","dateModified":"2026-09-14T06:39:15.349Z","description":"Java's Ahead-of-Time (AOT) cache, introduced in JDK 24 via JEP 483 and enhanced in JDK 25 and 26, lets the JVM save class-loading and linking work to disk so...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0aef58ddf52c2c440b51fefe6f0b7baa?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0aef58ddf52c2c440b51fefe6f0b7baa?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Baeldung","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Baeldung","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/52cccfb454d946c4b7dfa5e816f9e576","url":"https://daily.dev/sources/baeldung"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java,jvm","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Baeldung","item":"https://daily.dev/sources/baeldung"},{"@type":"ListItem","position":3,"name":"A Guide to Ahead-of-Time Cache in the Java"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/a-guide-to-ahead-of-time-cache-in-the-java-xfptxkmvl#faq","mainEntity":[{"@type":"Question","name":"How do I build a Java AOT cache in a single step instead of the three-phase workflow?","acceptedAnswer":{"@type":"Answer","text":"Pass a destination path to the -XX:AOTCacheOutput flag when running the app normally, for example java -XX:AOTCacheOutput=app.aot -cp app.jar com.example.App, and the JVM builds and writes the cache automatically on shutdown. JEP 514 also offers a two-step variant that records the cache once and reuses it in later runs via -XX:AOTCache=app.aot, without needing the older record/create/run split. Developers tuning JVM startup times can track AOT caching techniques like this on daily.dev."}},{"@type":"Question","name":"Why would I use the three-phase AOT cache workflow instead of the simpler one-step command in Java?","acceptedAnswer":{"@type":"Answer","text":"The one-step -XX:AOTCacheOutput approach spins up a second heap the same size as the training heap while assembling the cache, roughly doubling peak memory demand, for example needing about 4 GB with -Xms2g -Xmx2g settings. The three-phase record, create, and run workflow lets you record on a modest instance and assemble the cache on a larger one, which matters for small cloud servers with limited memory. Teams sizing cloud instances for Java deployments can weigh trade-offs like this via daily.dev."}},{"@type":"Question","name":"What conditions invalidate a Java AOT cache and force a rebuild?","acceptedAnswer":{"@type":"Answer","text":"A Java AOT cache is valid for a single build only, so a code change, a new or updated library, or a JDK upgrade each invalidates it, requiring regeneration alongside every build. Training and production runs must also stay aligned: same JAR timestamps, same JDK, hardware, and OS, plain JARs with no folders or wildcards on the classpath, and no JVMTI agents altering class loading at runtime. Developers maintaining Java build and deployment pipelines can keep tabs on caching pitfalls via daily.dev."}}]}
```

