<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BaoKhang</title>
    <description>The latest articles on DEV Community by BaoKhang (@baokhang83).</description>
    <link>https://dev.to/baokhang83</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4035271%2Fab34f96d-b419-4c94-b4f1-08b1ff036e9c.png</url>
      <title>DEV Community: BaoKhang</title>
      <link>https://dev.to/baokhang83</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baokhang83"/>
    <language>en</language>
    <item>
      <title>31% to 58% Faster Java Pods on Kubernetes: Benchmarking JDK 25 Leyden AOT from Microservices to a 458-JAR Monolith</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Sat, 14 Nov 2026 18:16:55 +0000</pubDate>
      <link>https://dev.to/baokhang83/31-to-58-faster-java-pods-on-kubernetes-benchmarking-jdk-25-leyden-aot-from-microservices-to-a-563c</link>
      <guid>https://dev.to/baokhang83/31-to-58-faster-java-pods-on-kubernetes-benchmarking-jdk-25-leyden-aot-from-microservices-to-a-563c</guid>
      <description>&lt;p&gt;OpenJDK 25's &lt;strong&gt;Project Leyden AOT caches&lt;/strong&gt; deliver GraalVM-like startup speedups without ahead-of-time compilation constraints or loss of peak JIT throughput. To test whether downloading large enterprise AOT archives on Kubernetes offsets these gains, we conducted a 32-cell controlled study on Google Kubernetes Engine (GKE) using &lt;a href="https://github.com" rel="noopener noreferrer"&gt;mnemo-warmup&lt;/a&gt; across four Spring Boot workload tiers (from a 54.3 MiB microservice up to a 223.5 MiB ThingsBoard CE monolith).&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Performance Findings
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single-Pod Readiness:&lt;/strong&gt; Single-pod startup times improved by &lt;strong&gt;31% to 58%&lt;/strong&gt;, cutting readiness time from 4.5s to 2.0s (-56%) on the minimal service and from 30.8s to 21.2s (-31%) on the ThingsBoard CE monolith.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network Overhead:&lt;/strong&gt; Fetching and SHA-256 verifying the 223.5 MiB archive over same-region GKE Artifact Registry took only &lt;strong&gt;0.7s&lt;/strong&gt; for single pods and &lt;strong&gt;0.9s&lt;/strong&gt; median during 9-pod HPA bursts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live HPA 1→9 Scale-Outs:&lt;/strong&gt; Per-pod readiness improved by &lt;strong&gt;22% to 49%&lt;/strong&gt; under load, dropping median per-pod &lt;code&gt;App Ready&lt;/code&gt; time from 55.3s to 43.3s on ThingsBoard and from 11.6s to 5.9s on the Standard tier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wall-Clock Speedups:&lt;/strong&gt; Total end-to-end HPA scale-out duration was cut in half on lighter services, dropping from 110.9s to 54.2s (-51%) on the Minimal tier.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Workload Tiers &amp;amp; Benchmark Summary
&lt;/h2&gt;

&lt;p&gt;Benchmarks ran on pinned Debian OpenJDK 25.0.4.1 (&lt;code&gt;linux/amd64&lt;/code&gt;) on GKE Standard (&lt;code&gt;12 vCPU / 64 GB E2&lt;/code&gt;):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Workload Tier&lt;/th&gt;
&lt;th&gt;App Stack / JAR Count&lt;/th&gt;
&lt;th&gt;AOT Archive Size&lt;/th&gt;
&lt;th&gt;Uncached Ready&lt;/th&gt;
&lt;th&gt;Best Cached Ready&lt;/th&gt;
&lt;th&gt;Max Speedup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;1. Minimal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Spring Web + Actuator (37 JARs)&lt;/td&gt;
&lt;td&gt;54.30 MiB&lt;/td&gt;
&lt;td&gt;4.5 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;2.0 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;-56% (-2.5 s)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;2. Standard&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Minimal + JPA/Hibernate, Postgres (70 JARs)&lt;/td&gt;
&lt;td&gt;103.88 MiB&lt;/td&gt;
&lt;td&gt;7.4 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3.1 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;-58% (-4.3 s)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;3. Larger&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Standard + OpenAPI, Kafka, RabbitMQ (98 JARs)&lt;/td&gt;
&lt;td&gt;115.97 MiB&lt;/td&gt;
&lt;td&gt;8.7 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3.9 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;-55% (-4.8 s)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;4. Heavy Monolith&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;ThingsBoard CE 4.3.1.8 + Postgres (458 JARs)&lt;/td&gt;
&lt;td&gt;223.52 MiB&lt;/td&gt;
&lt;td&gt;30.8 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;21.2 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;-31% (-9.6 s)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;(Full details, data tables, and reproducible harness scripts are available in&lt;/em&gt; &lt;a href="https://github.com/baokhang83/mnemo-warmup/blob/main/benchmarks/workload-tiers/README.md" rel="noopener noreferrer"&gt;&lt;em&gt;benchmarks/workload-tiers&lt;/em&gt;&lt;/a&gt;&lt;em&gt;).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With these validations complete, &lt;strong&gt;mnemo-warmup&lt;/strong&gt; transitions to its &lt;code&gt;v0.3.0&lt;/code&gt; &lt;strong&gt;beta&lt;/strong&gt; release.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions (FAQ)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What is&lt;/strong&gt; &lt;code&gt;mnemo-warmup&lt;/code&gt;&lt;strong&gt;?&lt;/strong&gt; An open-source Kubernetes automation tool for OpenJDK AppCDS and Project Leyden AOT caches that requires no code or Dockerfile changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How fast are Java pods with&lt;/strong&gt; &lt;code&gt;mnemo-warmup&lt;/code&gt;&lt;strong&gt;?&lt;/strong&gt; Single-pod readiness improves by &lt;strong&gt;31% to 58%&lt;/strong&gt;, while per-pod scaling times during HPA 1→9 bursts improve by &lt;strong&gt;22% to 49%&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do large archives cause network bottlenecks?&lt;/strong&gt; No; on same-region cloud networks, streaming a 223.5 MiB archive takes under 1 second while saving up to 12 seconds per pod.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How does it work without code changes?&lt;/strong&gt; It uses Kubernetes annotations, an asynchronous trainer &lt;code&gt;CronJob&lt;/code&gt;, and a static Go launcher that executes Java directly as PID 1.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What happens if the OCI registry fails?&lt;/strong&gt; The system is strictly fail-open; if an archive is missing or unverified, it falls back cleanly to a standard JVM boot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When is it least effective?&lt;/strong&gt; Speedups are minimal when startup is bottlenecked by disk I/O, multi-process wrapper scripts like SonarQube, or external database migration delays.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How does it compare to GraalVM Native Image?&lt;/strong&gt; It preserves full C2 JIT throughput, supports dynamic reflection/agents, and avoids long native-image builds.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>kubernetes</category>
      <category>java</category>
      <category>performance</category>
      <category>devops</category>
    </item>
    <item>
      <title>Can JVM caches speed up Spring Boot on Kubernetes? A JDK 21 and JDK 25 study</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Fri, 13 Nov 2026 16:34:32 +0000</pubDate>
      <link>https://dev.to/baokhang83/can-jvm-caches-speed-up-spring-boot-on-kubernetes-a-jdk-21-and-jdk-25-study-9p7</link>
      <guid>https://dev.to/baokhang83/can-jvm-caches-speed-up-spring-boot-on-kubernetes-a-jdk-21-and-jdk-25-study-9p7</guid>
      <description>&lt;h1&gt;
  
  
  Can JVM caches speed up Spring Boot on Kubernetes? A JDK 21 and JDK 25 study
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;A study of one Spring Boot workload found that mnemo-warmup reduced the application's reported startup time with both JDK 21 AppCDS and the JDK 25 AOT cache. With a 1 CPU and 1 GiB application limit, the median fell from 3.14 to 1.90 seconds on JDK 21 and from 3.23 to 1.47 seconds on JDK 25. In both cases, the median Kubernetes pod start-to-Ready remained 5 seconds.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That distinction matters. A JVM can start the application faster while container setup, archive fetching, readiness probes, and timestamp resolution leave the observed pod readiness time unchanged. Measure both before deciding whether a startup cache is useful for your service.&lt;/p&gt;

&lt;p&gt;This article describes a benchmark of &lt;a href="https://github.com/baokhang83/mnemo-warmup" rel="noopener noreferrer"&gt;mnemo-warmup&lt;/a&gt;, an open-source tool for training and distributing Java startup caches in Kubernetes. It is based on the &lt;a href="https://github.com/baokhang83/mnemo-warmup/blob/e4a8c3f/benchmarks/jdk21-vs-jdk25.md" rel="noopener noreferrer"&gt;study report and raw results&lt;/a&gt;. The results are measurements from one workload and environment, not a prediction for every Java application.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is mnemo-warmup?
&lt;/h2&gt;

&lt;p&gt;mnemo-warmup trains a JVM startup cache using an application's container image in a Kubernetes cluster. It stores the archive in an OCI registry and arranges for later pods to fetch a compatible archive at startup. A fingerprint of inputs such as the JDK, application JARs, and JVM options helps decide whether an archive fits the launch.&lt;/p&gt;

&lt;p&gt;The tool supports AppCDS, which shares prepared class metadata, and the JDK's AOT cache. In this study, its automatic selection used AppCDS with JDK 21 and AOT with JDK 25. The application remains a JVM application; this is a different deployment choice from compiling it to a GraalVM native executable.&lt;/p&gt;

&lt;p&gt;Training runs a real instance of the application. That means startup actions, such as connecting to services or applying migrations, can also happen during training. Operators need to review the trainer configuration and measure the deployment overhead as well as the JVM saving. The project describes itself as alpha in its &lt;a href="https://github.com/baokhang83/mnemo-warmup" rel="noopener noreferrer"&gt;README&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The experiment
&lt;/h2&gt;

&lt;p&gt;The benchmark used the same Spring Boot application, containing 70 JARs and about 59 MiB of application files, on Temurin JDK 21.0.13 and JDK 25.0.5. It ran on an Apple M5 laptop using Docker Desktop and a single-node, ARM64 kind cluster. The cache registry was local to the Docker network.&lt;/p&gt;

&lt;p&gt;There were four configurations: each JDK with no application resource limits, and each JDK with application requests and limits of 1 CPU and 1 GiB. For each configuration, the harness discarded a warm-up round and measured 12 rounds of three interleaved variants:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A pod without mnemo-warmup.&lt;/li&gt;
&lt;li&gt;A pod with mnemo-warmup but no archive in its store.&lt;/li&gt;
&lt;li&gt;A pod with mnemo-warmup and a trained archive.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The cached variant reported a successful fetch and archive use in all 12 measured pods in each configuration. The measurements below compare the first and third variants. The full &lt;a href="https://github.com/baokhang83/mnemo-warmup/blob/e4a8c3f/benchmarks/jdk21-vs-jdk25.md" rel="noopener noreferrer"&gt;study report&lt;/a&gt; includes the no-cache variant, ranges, environment, training records, registry samples, and links to raw pod data and logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results: application startup and pod readiness
&lt;/h2&gt;

&lt;p&gt;All values are medians. Application startup is taken from the Spring startup log. Pod start-to-Ready uses Kubernetes timestamps, which have whole-second resolution in this setup.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Configuration&lt;/th&gt;
&lt;th&gt;Application start without tool&lt;/th&gt;
&lt;th&gt;Application start with archive&lt;/th&gt;
&lt;th&gt;Pod start-to-Ready without / with archive&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JDK 21 AppCDS, no application limits&lt;/td&gt;
&lt;td&gt;1,328 ms&lt;/td&gt;
&lt;td&gt;693 ms&lt;/td&gt;
&lt;td&gt;3.0 / 3.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JDK 25 AOT, no application limits&lt;/td&gt;
&lt;td&gt;1,352 ms&lt;/td&gt;
&lt;td&gt;523 ms&lt;/td&gt;
&lt;td&gt;2.5 / 3.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JDK 21 AppCDS, 1 CPU / 1 GiB&lt;/td&gt;
&lt;td&gt;3,142 ms&lt;/td&gt;
&lt;td&gt;1,901 ms&lt;/td&gt;
&lt;td&gt;5.0 / 5.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JDK 25 AOT, 1 CPU / 1 GiB&lt;/td&gt;
&lt;td&gt;3,234 ms&lt;/td&gt;
&lt;td&gt;1,471 ms&lt;/td&gt;
&lt;td&gt;5.0 / 5.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Under the application limit, the measured median JVM startup saving was 1,242 ms for JDK 21 AppCDS and 1,763 ms for JDK 25 AOT, each compared with the no-tool baseline on the same JDK. Those are approximately 40% and 55% reductions in the application's reported startup time, respectively. They are &lt;strong&gt;not&lt;/strong&gt; reductions in pod start-to-Ready: both limited cached and uncached deployments had a median of 5 seconds.&lt;/p&gt;

&lt;p&gt;The no-limits JDK 25 comparison also shows why a faster application alone is not enough to establish a faster pod: its median cached pod start-to-Ready was 3.0 seconds, compared with 2.5 seconds without the tool. The timestamps and readiness probe in this experiment have approximately one-second resolution, so treat small differences with care.&lt;/p&gt;

&lt;h2&gt;
  
  
  What did the caches cost?
&lt;/h2&gt;

&lt;p&gt;The AppCDS archive was about 87 MB in both JDK 21 runs. The JDK 25 AOT archive was about 109 MB. Five direct downloads from the kind node to the local registry had median times of roughly 24 ms for AppCDS and 30 ms for AOT. These are local-network results, not remote-registry performance measurements.&lt;/p&gt;

&lt;p&gt;The trainer container ran for 4 seconds in each JDK 21 run and for 5 and 6 seconds in the two JDK 25 runs. Those are single observations, measured from container start to finish. They include work beyond producing the archive. The trainer had no CPU or memory limits, even when the application pods were limited.&lt;/p&gt;

&lt;h2&gt;
  
  
  When might mnemo-warmup be worth evaluating?
&lt;/h2&gt;

&lt;p&gt;Consider a measured trial if you run Java services on Kubernetes, want to retain JVM deployment, and application startup is a meaningful part of rollout or scale-out time. A cluster-trained cache may be useful when the cluster's actual JDK and launch options differ from assumptions made during an image build. Compare against any cache already in the image; another training step and archive download may add cost without enough benefit.&lt;/p&gt;

&lt;p&gt;Use caution when a workload already supplies JVM cache flags. In a separate local OpenJDK 25.0.1 check, combining &lt;code&gt;-XX:AOTCache&lt;/code&gt; in &lt;code&gt;JAVA_TOOL_OPTIONS&lt;/code&gt; with &lt;code&gt;-XX:SharedArchiveFile&lt;/code&gt; on the command line stopped JVM initialization. The project's &lt;a href="https://github.com/baokhang83/mnemo-warmup/blob/e4a8c3f/docs/operations.md#images-with-a-build-time-cache" rel="noopener noreferrer"&gt;operations guide&lt;/a&gt; describes that limit. Preview warnings identify possible cache markers; they do not establish which flags a Kubernetes workload will ultimately use or guarantee compatibility.&lt;/p&gt;

&lt;p&gt;If pod setup, network downloads, readiness checks, or application work outside class loading dominate startup, a faster JVM start may not improve the time users wait for a ready pod. Teams already satisfied with an image-baked cache or a native executable should benchmark those choices against the cluster-trained approach on their own workload.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this study does and does not establish
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It measures one Spring Boot application, one ARM64 laptop and one local kind cluster. Results may differ on other applications, processors and production nodes.&lt;/li&gt;
&lt;li&gt;JDK version and cache mechanism changed together. The experiment does not isolate AppCDS versus AOT on the same JDK.&lt;/li&gt;
&lt;li&gt;The three variants were interleaved within each configuration, but JDK configurations were run sequentially. Machine conditions can drift between them.&lt;/li&gt;
&lt;li&gt;The registry was local, images were already available, and pods started one at a time. The study does not measure remote registry latency, image pulls, or concurrent scale-out.&lt;/li&gt;
&lt;li&gt;One limited JDK 21 no-cache application start took 21.3 seconds. It remains in the raw data and reported ranges.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to evaluate it on your application
&lt;/h2&gt;

&lt;p&gt;Start with the &lt;a href="https://github.com/baokhang83/mnemo-warmup" rel="noopener noreferrer"&gt;mnemo-warmup README&lt;/a&gt;, then read the &lt;a href="https://github.com/baokhang83/mnemo-warmup/blob/main/benchmarks/README.md" rel="noopener noreferrer"&gt;benchmark method and results&lt;/a&gt; and &lt;a href="https://github.com/baokhang83/mnemo-warmup/blob/main/docs/operations.md" rel="noopener noreferrer"&gt;operations guide&lt;/a&gt;. Compare repeated deployments with and without the tool under representative CPU and memory limits. Record application startup, pod start-to-Ready, archive size, download time, training cost, and failure behavior. Include any existing image-baked cache as its own baseline.&lt;/p&gt;

&lt;p&gt;For this workload, mnemo-warmup made the Java application report startup sooner. The experiment did not show a lower median pod readiness time in the limited configuration.&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>performance</category>
      <category>java</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>Faster Java Pod Startups Without GraalVM: Why AppCDS Needs Kubernetes Image Volumes</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Thu, 12 Nov 2026 01:43:17 +0000</pubDate>
      <link>https://dev.to/baokhang83/faster-java-pod-startups-without-graalvm-why-appcds-needs-kubernetes-image-volumes-5dgf</link>
      <guid>https://dev.to/baokhang83/faster-java-pod-startups-without-graalvm-why-appcds-needs-kubernetes-image-volumes-5dgf</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Correction:&lt;/strong&gt; An earlier version described the Spring Boot image-volume result as 2 seconds (40%) faster based on the difference between separate group medians. The median paired improvement against a plain deployment was 1 second. The readiness timestamps have 1-second resolution.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you run Java workloads on Kubernetes, you have probably stared at slow pod readiness metrics during a deployment or autoscaling event. The JVM's cold-start work—loading, verifying, and linking thousands of classes—can make scaling painful.&lt;/p&gt;

&lt;p&gt;One option is to compile your application into a GraalVM Native Image. This can deliver fast startups, but it can also require longer builds and changes to accommodate closed-world reflection constraints, Java agents, and libraries.&lt;/p&gt;

&lt;p&gt;OpenJDK offers a middle ground: &lt;strong&gt;Application Class-Data Sharing (AppCDS)&lt;/strong&gt; on JDK 21+ and &lt;strong&gt;Project Leyden AOT caches&lt;/strong&gt; on JDK 25+. These features let the JVM store prepared class data in an archive on disk for reuse in subsequent runs.&lt;/p&gt;

&lt;p&gt;When I started building &lt;a href="https://github.com/baokhang83/mnemo-warmup" rel="noopener noreferrer"&gt;&lt;strong&gt;mnemo-warmup&lt;/strong&gt;&lt;/a&gt;—an open-source tool that automates training and sharing AppCDS/Leyden caches inside Kubernetes without changing application source code—I wanted to answer a simple engineering question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Does a Kubernetes pod actually become Ready sooner once you pay the infrastructure tax of fetching, verifying, and mounting the cache?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After running hundreds of automated cold-restart benchmarks across different JVM architectures, the answer was: &lt;strong&gt;It depends on how you deliver the tooling and what your application does during startup.&lt;/strong&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  The Hidden Infrastructure Tax: Init Containers
&lt;/h3&gt;

&lt;p&gt;One way to deliver a shared cache archive to a stateless pod uses init containers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An install init container copies the launcher tools onto a shared &lt;code&gt;emptyDir&lt;/code&gt; volume.&lt;/li&gt;
&lt;li&gt;A fetch init container pulls the trained archive from an OCI registry and verifies its SHA-256 digest.&lt;/li&gt;
&lt;li&gt;The main application container boots the JVM pointing to the shared archive.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In practice, measuring the timeline from &lt;code&gt;pod.status.startTime&lt;/code&gt; to &lt;code&gt;Ready&lt;/code&gt; revealed a bottleneck.&lt;/p&gt;

&lt;p&gt;In our initial benchmarks running a heavy Spring Boot application (69 JARs, constrained to 1 CPU / 1 GiB), the AppCDS archive cut the application's reported startup time from &lt;strong&gt;3.18s to 1.88s&lt;/strong&gt;. Yet the separately calculated median pod readiness times were both &lt;strong&gt;5 seconds&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Even after rewriting our helper utilities from Java into static Go binaries (dropping tool execution time from ~1,050ms to ~140ms), the pod was still losing nearly &lt;strong&gt;1.75 seconds&lt;/strong&gt; before the main application began. In this setup, init-container lifecycle and orchestration overhead consumed the observed startup savings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Kubernetes Image Volumes
&lt;/h3&gt;

&lt;p&gt;To reduce the init-container overhead, we tested Kubernetes &lt;code&gt;image&lt;/code&gt; volumes (introduced as beta in Kubernetes 1.33+ and supported by containerd 2.1+).&lt;/p&gt;

&lt;p&gt;An &lt;code&gt;image&lt;/code&gt; volume allows the container runtime to mount the read-only OCI tools layer directly into the application container's filesystem at launch. Our static launcher runs as the entrypoint, fetches the archive directly, and replaces itself with &lt;code&gt;java&lt;/code&gt; via &lt;code&gt;exec&lt;/code&gt; so the JVM remains PID 1.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Workload&lt;/th&gt;
&lt;th&gt;Plain deployment (&lt;code&gt;none&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Init containers (&lt;code&gt;cached&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Image volume (&lt;code&gt;cached&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🟢 &lt;strong&gt;Spring Boot&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;5 s&lt;/td&gt;
&lt;td&gt;5 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;1 s faster median paired result&lt;/strong&gt; with image volumes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🟡 &lt;strong&gt;Jenkins LTS&lt;/strong&gt; (2.492.3)&lt;/td&gt;
&lt;td&gt;4 s&lt;/td&gt;
&lt;td&gt;5 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;4 s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0 s median paired difference&lt;/strong&gt; with image volumes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔴 &lt;strong&gt;SonarQube&lt;/strong&gt; (26.11)&lt;/td&gt;
&lt;td&gt;15 s&lt;/td&gt;
&lt;td&gt;17 s&lt;/td&gt;
&lt;td&gt;&lt;em&gt;Not run&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Init-container arm was slower&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;The table shows separately calculated group medians over 12 cold restarts on a local kind cluster. The Spring Boot median of the per-round paired differences was −1 second, even though the separate group medians differ by 2 seconds. Kubernetes pod condition timestamps have 1-second resolution, so these readiness measurements are coarse. SonarQube ran with 2 CPU / 3 GiB; the other workloads used 1 CPU / 1 GiB.&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Three Lessons on Workload Suitability
&lt;/h3&gt;

&lt;p&gt;Testing three distinct applications illustrated how results can differ across workloads.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Framework-Heavy Apps Can Benefit (Spring Boot)
&lt;/h4&gt;

&lt;p&gt;Framework-heavy applications load many classes and perform substantial initialization during startup. In our Spring Boot image-volume test, the application's self-reported startup time fell from a median of &lt;strong&gt;3,182 ms to 1,900 ms&lt;/strong&gt; with AppCDS.&lt;/p&gt;

&lt;p&gt;For pod readiness, the &lt;strong&gt;median paired improvement was 1 second&lt;/strong&gt; against a plain deployment—roughly 20% of the plain group's 5-second median. The separate group medians were 5 seconds and 3 seconds, but subtracting those medians overstates the median paired improvement. The readiness timestamps have only 1-second resolution, so a higher-resolution follow-up would help refine the estimate.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. I/O and Plugin-Bound Apps Hit Parity (Jenkins)
&lt;/h4&gt;

&lt;p&gt;Jenkins is a large Java application, making it seem like an ideal candidate for AppCDS. However, while the archive successfully loaded 85% of Jenkins' classes and shaved ~300ms off the reported application startup, the median paired pod readiness difference was &lt;strong&gt;0 seconds&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Jenkins startup includes tasks that class-data sharing cannot directly accelerate: unpacking bundled archives, parsing XML configurations on disk, and executing sequential plugin initialization hooks. These activities may limit the impact of class-loading improvements on overall readiness.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Multi-Process Wrappers Bypass the Cache (SonarQube)
&lt;/h4&gt;

&lt;p&gt;SonarQube proved to be an important architectural edge case. In our test harness (run at 2 CPU / 3 GiB), training succeeded and all 12 pods validated and loaded the archive. Yet the init-container group's median readiness was 2 seconds slower than the plain group's median.&lt;/p&gt;

&lt;p&gt;SonarQube's container entrypoint launches a Java coordinator process, which then spawns separate child JVMs for Elasticsearch, the web server, and the compute engine. Because the wrapper passes &lt;code&gt;-XX:SharedArchiveFile&lt;/code&gt; to the parent entrypoint command, the child JVMs do not receive that flag automatically. The image-volume configuration was not tested for this workload.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Rule of Thumb
&lt;/h3&gt;

&lt;p&gt;If you are evaluating AppCDS or Project Leyden for your Kubernetes clusters, consider these three factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Check your delivery mechanism:&lt;/strong&gt; In our tests, init-container overhead offset the startup gains for the Spring Boot workload. Image volumes avoided those init containers and produced a net improvement. Measure the full pod-to-Ready path on your own cluster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Profile your startup bottleneck:&lt;/strong&gt; Applications that spend substantial time loading classes may benefit, but the pod-level gain depends on the rest of startup and the cache delivery overhead. Workloads dominated by disk I/O, migrations, or network waits may see little benefit. These results do not establish a general percentage improvement for Spring Boot, Micronaut, or other frameworks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch out for wrapper scripts:&lt;/strong&gt; If your container launches a supervisor process that forks downstream child JVMs, those child processes will bypass the cache unless explicitly configured.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What's Next for &lt;code&gt;mnemo-warmup&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;mnemo-warmup&lt;/code&gt; is currently in active &lt;strong&gt;alpha&lt;/strong&gt;. Before tagging our beta, we are running the next wave of studies: comparing &lt;strong&gt;JDK 21 AppCDS against JDK 25 Project Leyden AOT&lt;/strong&gt; archive sizes, mapping out the &lt;strong&gt;application size break-even curve&lt;/strong&gt; (from 40 MB microservices to 350 MB monoliths), and simulating &lt;strong&gt;HPA scale-out bursts&lt;/strong&gt; against remote cloud registries. We also plan to investigate higher-resolution readiness measurements, while accounting for watch delivery latency and readiness-probe timing.&lt;/p&gt;

&lt;p&gt;If you want to inspect the raw benchmark CSVs, reproduce the cluster tests on your own hardware, or weigh in on making &lt;code&gt;image&lt;/code&gt; volumes our default delivery mode, check out the repository at &lt;a href="https://github.com/baokhang83/mnemo-warmup" rel="noopener noreferrer"&gt;&lt;strong&gt;mnemo-warmup&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>java</category>
      <category>performance</category>
    </item>
    <item>
      <title>Predictive Test Selection Without SaaS Lock-In: Storing TIA Indexes in GitHub Actions Cache or S3</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Mon, 09 Nov 2026 10:21:02 +0000</pubDate>
      <link>https://dev.to/baokhang83/predictive-test-selection-without-saas-lock-in-storing-tia-indexes-in-github-actions-cache-or-s3-5coo</link>
      <guid>https://dev.to/baokhang83/predictive-test-selection-without-saas-lock-in-storing-tia-indexes-in-github-actions-cache-or-s3-5coo</guid>
      <description>&lt;p&gt;Hosted predictive test selection products solve a real problem, and they come with a procurement conversation: another vendor, another bill, and a security review about sending build and test metadata to someone else's servers. Some teams clear that review. Plenty do not, or cannot justify the budget for a suite that is only slow, not on fire.&lt;/p&gt;

&lt;p&gt;There is a smaller, older idea that needs none of it: &lt;strong&gt;test impact analysis from a saved dependency map, stored wherever you already store build state.&lt;/strong&gt; This post shows a complete self-hosted CI architecture for it with &lt;a href="https://github.com/baokhang83/blastradius" rel="noopener noreferrer"&gt;blastradius&lt;/a&gt;, using either the GitHub Actions cache or a private S3 bucket. I ran both paths end to end on fresh clones so the setup, and the places it breaks, are tested rather than described.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually gets stored
&lt;/h2&gt;

&lt;p&gt;Before you decide where it can live, look at what it is. After a base-branch build, blastradius writes an index that maps each test to the production classes it loaded. A single entry looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"className"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"demo.ParserCase34Test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"methodName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"applies"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependsOnClasses"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"demo.ParserCase34Test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"demo.Parser"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The whole file also holds the commit SHA the index was built from, a timestamp, direct-invocation records, and a list of "ambient" classes (JDK and framework classes, mostly). It is class names and test names. It is not source code, test output or data. For my 120-test fixture the index was about 175 KB, and about 53 KB compressed in a cache tarball.&lt;/p&gt;

&lt;p&gt;That is still metadata about your codebase's structure, so treat it as internal. Two practical rules from the project docs: do not put credentials or other secrets under &lt;code&gt;.blastradius/&lt;/code&gt;, and remember that GitHub Actions caches are readable by pull-request workflows.&lt;/p&gt;

&lt;p&gt;On "nothing leaves your infrastructure": the tool reads and writes a local directory or the S3 bucket you configure. I searched the plugin, core and S3 modules for hard-coded service endpoints and found none beyond the AWS SDK itself. That is a grep, not an audit, so do your own review if your policy requires one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; push to main                                   pull request
 ─────────────                                  ────────────
 mvn verify                                     restore index
   └─ TRACK: full suite + agent                   └─ SELECT: diff vs merge base
        │                                              │
        ▼                                              ▼
   .blastradius/&amp;lt;main-sha&amp;gt;/index.json ──store──▶  run only matching tests
        (GitHub Actions cache  or  S3 bucket)         (missing index → full suite)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two jobs, one artifact:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Trunk job (TRACK).&lt;/strong&gt; Runs the full suite with a Java agent attached and writes the index for that commit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PR job (SELECT).&lt;/strong&gt; Restores the newest trunk index, diffs the PR against its Git merge base, and narrows Surefire/Failsafe to the tests whose recorded classes changed. If no usable index exists, it runs the full suite.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Everything else is plumbing: how the index travels from job 1 to job 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Option 1: GitHub Actions cache (no extra infrastructure)
&lt;/h2&gt;

&lt;p&gt;For most teams this is the right default. No bucket, no IAM, nothing outside GitHub.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;build&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;main&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;verify&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;fetch-depth&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;            &lt;span class="c1"&gt;# the merge base must be reachable&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-java@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;distribution&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;temurin&lt;/span&gt;
          &lt;span class="na"&gt;java-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;21'&lt;/span&gt;
          &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;maven&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Restore Blastradius index&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;blastradius-index&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/cache/restore@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.blastradius&lt;/span&gt;
          &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;blastradius-index-${{ runner.os }}-${{ github.sha }}&lt;/span&gt;
          &lt;span class="na"&gt;restore-keys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
            &lt;span class="s"&gt;blastradius-index-${{ runner.os }}-&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mvn -B --no-transfer-progress verify&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Save Blastradius index (main only)&lt;/span&gt;
        &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.ref == 'refs/heads/main' &amp;amp;&amp;amp; success() &amp;amp;&amp;amp; steps.blastradius-index.outputs.cache-hit != 'true' }}&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/cache/save@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.blastradius&lt;/span&gt;
          &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;blastradius-index-${{ runner.os }}-${{ github.sha }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why it is shaped this way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Save only from successful &lt;code&gt;main&lt;/code&gt; builds.&lt;/strong&gt; PRs read an index made by the trusted base branch and never write one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key by commit SHA.&lt;/strong&gt; Each main build saves an immutable snapshot. A PR has a new SHA, so the exact lookup misses and &lt;code&gt;restore-keys&lt;/code&gt; falls back to the newest &lt;code&gt;main&lt;/code&gt; snapshot, which is what you want.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;success()&lt;/code&gt; before saving.&lt;/strong&gt; A failed build should not become tomorrow's baseline.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the plugin, with the base reference set to &lt;code&gt;origin/main&lt;/code&gt; (see the first gotcha below for why):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.github.baokhang83.blastradius&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;blastradius-maven-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;0.4.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;executions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;process-test-classes&lt;span class="nt"&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;goals&amp;gt;&amp;lt;goal&amp;gt;&lt;/span&gt;select&lt;span class="nt"&gt;&amp;lt;/goal&amp;gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/executions&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;baseRef&amp;gt;&lt;/span&gt;origin/main&lt;span class="nt"&gt;&amp;lt;/baseRef&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Option 2: a private S3 bucket
&lt;/h2&gt;

&lt;p&gt;Use S3 when your runners cannot share a reliable workspace cache: self-hosted runners on different machines, several CI systems, or a cache you do not trust to stay warm. The index is written to and read from the bucket directly, so no cache steps are needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;baseRef&amp;gt;&lt;/span&gt;origin/main&lt;span class="nt"&gt;&amp;lt;/baseRef&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;indexStore&amp;gt;&lt;/span&gt;s3&lt;span class="nt"&gt;&amp;lt;/indexStore&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;s3Bucket&amp;gt;&lt;/span&gt;ci-dependency-indexes&lt;span class="nt"&gt;&amp;lt;/s3Bucket&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;s3Prefix&amp;gt;&lt;/span&gt;blastradius&lt;span class="nt"&gt;&amp;lt;/s3Prefix&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;s3Region&amp;gt;&lt;/span&gt;eu-central-1&lt;span class="nt"&gt;&amp;lt;/s3Region&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- &amp;lt;s3Endpoint&amp;gt;https://minio.example.com&amp;lt;/s3Endpoint&amp;gt;  optional, S3-compatible stores --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The object key is derived from the commit: &lt;code&gt;blastradius/.blastradius/&amp;lt;commit-sha&amp;gt;/index.json&lt;/code&gt;. Credentials come from the standard AWS credential chain, so nothing secret goes in the POM.&lt;/p&gt;

&lt;p&gt;For GitHub Actions, prefer OIDC and a short-lived role over long-lived access keys. The plugin needs only &lt;code&gt;s3:GetObject&lt;/code&gt; and &lt;code&gt;s3:PutObject&lt;/code&gt; on the prefix, and does not need to list the bucket:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"s3:GetObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"s3:PutObject"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::&amp;lt;BUCKET&amp;gt;/&amp;lt;PREFIX&amp;gt;/*"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Give the &lt;code&gt;main&lt;/code&gt; job a role that can write, and give PR jobs a separate read-only role (&lt;code&gt;s3:GetObject&lt;/code&gt; only) if PRs may read the bucket at all. Do not grant either to untrusted fork pull requests; let those fall back to the full suite.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
  &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;

&lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
    &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;fetch-depth&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;aws-actions/configure-aws-credentials@v4&lt;/span&gt;
    &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;role-to-assume&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;arn:aws:iam::&amp;lt;ACCOUNT_ID&amp;gt;:role/blastradius-index-writer&lt;/span&gt;
      &lt;span class="na"&gt;aws-region&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;eu-central-1&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mvn -B --no-transfer-progress verify&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What I tested
&lt;/h2&gt;

&lt;p&gt;All runs used a small synthetic fixture (six utility classes, 60 two-test JUnit 5 classes, so 120 tests), Maven 3.9.12, JDK 25 and blastradius 0.4.0. Each job ran in a &lt;strong&gt;fresh clone with no shared files&lt;/strong&gt;, mimicking &lt;code&gt;actions/checkout&lt;/code&gt; on an empty runner. The PR changes one line in one utility class.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;How the index travelled&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Main job&lt;/td&gt;
&lt;td&gt;tracking build on a fresh clone&lt;/td&gt;
&lt;td&gt;TRACK, 120 / 120 tests, index written&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PR job, cache restored&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;.blastradius/&lt;/code&gt; extracted from the main job's tarball&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;SELECT, 20 / 120 tests (83.3% skipped)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PR job, cache miss&lt;/td&gt;
&lt;td&gt;nothing restored&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;FALLBACK&lt;/strong&gt;, 120 / 120 tests, build passes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PR job, S3&lt;/td&gt;
&lt;td&gt;read from the bucket the main job wrote to&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;SELECT, 20 / 120 tests (83.3% skipped)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Caveats, so you read this correctly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The cache path was simulated by tarring and untarring &lt;code&gt;.blastradius/&lt;/code&gt;, which is what &lt;code&gt;actions/cache&lt;/code&gt; does. I did not run it on real GitHub-hosted runners.&lt;/li&gt;
&lt;li&gt;The S3 path ran against a local S3-compatible server (moto), not real AWS S3. I did not test IAM, OIDC role assumption or bucket policies. The endpoint, bucket and prefix behavior is the same code path as MinIO or any S3-compatible store, but verify your IAM setup separately.&lt;/li&gt;
&lt;li&gt;83.3% reflects an evenly partitioned toy project. The realistic figure is the &lt;a href="https://baokhang.hashnode.dev/how-we-cut-maven-junit5-test-runs-61-percent-apache-repos" rel="noopener noreferrer"&gt;historical replay&lt;/a&gt;: 61.4% fewer test executions across 800 commits on four open-source projects, counted as executions rather than wall-clock time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The cache-miss row is the safety property that matters for this architecture: &lt;strong&gt;losing the index costs you speed, never correctness.&lt;/strong&gt; A missing, unreadable or mismatched index produces a full run, not a guess.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas I hit
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;actions/checkout&lt;/code&gt; on a PR has no local &lt;code&gt;main&lt;/code&gt;, and the build fails.&lt;/strong&gt; On a pull request, &lt;code&gt;actions/checkout&lt;/code&gt; leaves you on a detached commit with only remote-tracking refs. With &lt;code&gt;&amp;lt;baseRef&amp;gt;main&amp;lt;/baseRef&amp;gt;&lt;/code&gt; the build failed outright:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;base reference "main" does not resolve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Setting &lt;code&gt;&amp;lt;baseRef&amp;gt;origin/main&amp;lt;/baseRef&amp;gt;&lt;/code&gt; fixed it, and it still behaves as the base reference on the push-to-main job, where it is the current commit. Pair it with &lt;code&gt;fetch-depth: 0&lt;/code&gt; so the merge base is reachable. Note that a &lt;code&gt;-DbaseRef=origin/main&lt;/code&gt; flag did not override a &lt;code&gt;&amp;lt;baseRef&amp;gt;&lt;/code&gt; hard-coded in the POM in my test, so set it in the POM (or make the POM read a property).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Cache eviction turns into full runs.&lt;/strong&gt; GitHub evicts caches that have not been accessed for a while and enforces a per-repository size limit. If &lt;code&gt;main&lt;/code&gt; is quiet for long enough, the next PR misses and runs everything. That is safe but slow, so make sure something on &lt;code&gt;main&lt;/code&gt; runs regularly (a scheduled workflow works) to keep a fresh snapshot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Tracking can fail without failing the build.&lt;/strong&gt; If the tracking agent is not attached to the test JVM, the build passes and logs &lt;code&gt;tracking failed ... falling back to the full suite&lt;/code&gt;, and no index is saved. I found this with JaCoCo plus an explicit &lt;code&gt;@{argLine}&lt;/code&gt; in Surefire; the fix is in the JaCoCo post in this series. Whatever your storage choice, grep the main job's log for &lt;code&gt;[blastradius] TRACK&lt;/code&gt; and for the absence of &lt;code&gt;tracking failed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Forks.&lt;/strong&gt; Fork PRs do not receive secrets or OIDC roles, so they cannot use S3, and they may not restore your cache. They fall back to the full suite, which is the correct behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cache or S3?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;GitHub Actions cache&lt;/th&gt;
&lt;th&gt;Private S3 bucket&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Extra infrastructure&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;bucket, IAM, optionally OIDC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Works across different runner fleets&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Survives long quiet periods on &lt;code&gt;main&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;no (eviction)&lt;/td&gt;
&lt;td&gt;yes (until you delete it)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Access control&lt;/td&gt;
&lt;td&gt;repo-level, readable by PR workflows&lt;/td&gt;
&lt;td&gt;IAM policy per role&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;most GitHub-hosted setups&lt;/td&gt;
&lt;td&gt;self-hosted runners, multi-CI, stricter access control&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Start with the cache. Move to S3 when eviction, runner topology or access control gives you a reason.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you give up versus a hosted service
&lt;/h2&gt;

&lt;p&gt;Be honest about the trade. A dependency-based tool like this one is deterministic and self-contained, and it has no model that learns from failure history, no hosted dashboard and no cross-project analytics. You own index freshness, and you own the policy for when to fall back. If those hosted features are what you need, and your security and budget allow it, a hosted product may be the better fit. If your constraint is "no new vendor, no data leaving our accounts", this is a workable alternative.&lt;/p&gt;

&lt;p&gt;Either way, keep a regular full-suite run (daily is the recommendation) as a backstop. Selection is sound by default, not a guarantee.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can I run predictive test selection in Maven without a SaaS product?
&lt;/h3&gt;

&lt;p&gt;Yes. Dependency-based test impact analysis needs only a saved map of which classes each test loads. Blastradius builds that map on your base branch and stores it in a local directory, the GitHub Actions cache or an S3 bucket you own.&lt;/p&gt;

&lt;h3&gt;
  
  
  What data does the index contain?
&lt;/h3&gt;

&lt;p&gt;Test class and method names, the production class names each test loaded, the commit SHA and a timestamp. It does not contain source code, test output or data. It is still internal metadata, so keep it out of public buckets and do not store secrets alongside it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need S3?
&lt;/h3&gt;

&lt;p&gt;No. The default file store plus a GitHub Actions cache is enough on GitHub-hosted runners. S3 is for runners that cannot share a cache, or when you want IAM-level access control.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens if the cache or bucket is empty?
&lt;/h3&gt;

&lt;p&gt;The PR build runs in &lt;code&gt;FALLBACK&lt;/code&gt; mode and executes the full suite. Nothing is skipped on a guess.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does my PR build fail with "base reference does not resolve"?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;actions/checkout&lt;/code&gt; on a pull request provides no local &lt;code&gt;main&lt;/code&gt; branch. Use &lt;code&gt;origin/main&lt;/code&gt; as the base reference and &lt;code&gt;fetch-depth: 0&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it work with Gradle?
&lt;/h3&gt;

&lt;p&gt;There is a Gradle plugin in the repository with the same cache and S3 settings, but at the time of writing it is not yet published to the Gradle Plugin Portal. The Maven plugin is on Maven Central.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is skipping tests safe?
&lt;/h3&gt;

&lt;p&gt;Selection is sound by default but not guaranteed. Reflection, generated code and string-dispatched APIs can escape dependency tracking. Keep a scheduled full-suite run as a safety net.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I am the author of blastradius.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>githubactions</category>
      <category>aws</category>
      <category>testing</category>
    </item>
    <item>
      <title>How to Run Test Impact Analysis in Maven Without Breaking JaCoCo Code Coverage</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Mon, 09 Nov 2026 10:04:02 +0000</pubDate>
      <link>https://dev.to/baokhang83/how-to-run-test-impact-analysis-in-maven-without-breaking-jacoco-code-coverage-32ec</link>
      <guid>https://dev.to/baokhang83/how-to-run-test-impact-analysis-in-maven-without-breaking-jacoco-code-coverage-32ec</guid>
      <description>&lt;p&gt;Test impact analysis (TIA) and code coverage both want the same thing from your build: a seat on the test JVM's command line. Coverage tools attach a Java agent through &lt;code&gt;argLine&lt;/code&gt;. Many TIA tools do too. When two agents, or two plugins writing the same property, meet in one &lt;code&gt;argLine&lt;/code&gt;, the usual outcomes are a corrupted &lt;code&gt;jacoco.exec&lt;/code&gt;, an empty report, or a team quietly turning coverage off on pull requests.&lt;/p&gt;

&lt;p&gt;This post walks through how &lt;a href="https://github.com/baokhang83/blastradius" rel="noopener noreferrer"&gt;blastradius&lt;/a&gt; avoids that on pull requests, where the one setup that &lt;em&gt;does&lt;/em&gt; collide on the base branch is, and the one-property fix. Everything here comes from a small fixture I built and ran, so the results are reproducible rather than asserted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the collision comes from
&lt;/h2&gt;

&lt;p&gt;JaCoCo's &lt;code&gt;prepare-agent&lt;/code&gt; goal writes a &lt;code&gt;-javaagent:&lt;/code&gt; option into a Maven property, &lt;code&gt;argLine&lt;/code&gt; by default. Surefire then reads that property when it forks the test JVM. A TIA tool that records which classes each test loads needs its own agent in the same fork, so both want to write &lt;code&gt;argLine&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Where they disagree is &lt;em&gt;when&lt;/em&gt; each one needs it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recording dependencies needs the agent &lt;strong&gt;once&lt;/strong&gt;, on a trusted baseline build.&lt;/li&gt;
&lt;li&gt;Using the recording needs &lt;strong&gt;no agent at all&lt;/strong&gt;. It only needs to decide which tests to run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Blastradius is built around that split.&lt;/p&gt;

&lt;h2&gt;
  
  
  TRACK on the base branch, SELECT on pull requests
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;TRACK (base branch).&lt;/strong&gt; The select goal forks a nested &lt;code&gt;mvn clean test&lt;/code&gt; with the dependency-recording agent appended to &lt;code&gt;argLine&lt;/code&gt;. During that run the agent records, for each test, the production classes it loaded. The result is saved as an index under &lt;code&gt;.blastradius/&lt;/code&gt;. This is the only point where blastradius adds a Java agent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SELECT (pull requests).&lt;/strong&gt; Blastradius diffs the commit against the Git merge base, compares the changed classes with the saved index, and narrows Surefire with the standard &lt;code&gt;test&lt;/code&gt; filter, the same property &lt;code&gt;-Dtest=&lt;/code&gt; sets. If nothing is selected it sets &lt;code&gt;skipTests&lt;/code&gt;. It does not touch &lt;code&gt;argLine&lt;/code&gt;, so your JaCoCo agent, your custom flags, and any other tooling run exactly as they do in a normal build.&lt;/p&gt;

&lt;p&gt;That is the part worth emphasising: on the builds developers wait for, the only change is &lt;em&gt;which tests&lt;/em&gt; run, not &lt;em&gt;how the test JVM is launched&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I measured
&lt;/h2&gt;

&lt;p&gt;The fixture is one Maven module with six small utility classes and 60 two-test JUnit 5 classes (120 tests). Each test class exercises exactly one utility class. Tooling: Maven 3.9.12, JDK 25, Surefire 3.5.2, JaCoCo 0.8.13, JUnit 5.10.2, blastradius 0.4.0. It is synthetic on purpose, so treat the numbers as an illustration of behavior, not a benchmark.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does base-branch tracking survive JaCoCo?
&lt;/h3&gt;

&lt;p&gt;I ran the TRACK build on &lt;code&gt;main&lt;/code&gt; with four configurations:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setup&lt;/th&gt;
&lt;th&gt;JaCoCo&lt;/th&gt;
&lt;th&gt;Surefire &lt;code&gt;argLine&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;Tracking result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;default&lt;/td&gt;
&lt;td&gt;index built&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;prepare-agent&lt;/code&gt; (defaults)&lt;/td&gt;
&lt;td&gt;default (not set)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;index built&lt;/strong&gt;, JaCoCo 6/6 lines&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;prepare-agent&lt;/code&gt; (defaults)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;argLine&amp;gt;@{argLine} -Dcustom.flag=on&amp;lt;/argLine&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;tracking failed, no index&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;D&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;prepare-agent&lt;/code&gt; with &lt;code&gt;propertyName=jacocoArgLine&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;argLine&amp;gt;@{jacocoArgLine} ${argLine} -Dcustom.flag=on&amp;lt;/argLine&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;index built&lt;/strong&gt;, JaCoCo 6/6 lines&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Setup C is the one to watch, because it is also the most common way people write a JaCoCo-plus-custom-flags configuration. With it, blastradius logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[WARNING] [blastradius] tracking failed; discarding its incomplete dependency data and falling back to the full suite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The build still passes and the tests still run, so nothing breaks loudly. But no index is saved, which means every pull request build afterwards has nothing to select against and runs the full suite. You keep your coverage and lose the speedup, which is easy to miss.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why setup C fails
&lt;/h3&gt;

&lt;p&gt;In the forked tracking build, blastradius passes its agent on the command line as &lt;code&gt;-DargLine=...&lt;/code&gt;. JaCoCo's &lt;code&gt;prepare-agent&lt;/code&gt; reads and writes the &lt;em&gt;project&lt;/em&gt; property &lt;code&gt;argLine&lt;/code&gt;, which does not include that command-line value. It sets &lt;code&gt;argLine&lt;/code&gt; to the JaCoCo agent alone, and an explicit &lt;code&gt;&amp;lt;argLine&amp;gt;@{argLine} ...&amp;lt;/argLine&amp;gt;&lt;/code&gt; in Surefire then resolves to exactly that. The tracking agent never reaches the test JVM, nothing is recorded, and blastradius correctly refuses to trust an empty recording.&lt;/p&gt;

&lt;p&gt;(I confirmed this by running the same nested command by hand: the build logged &lt;code&gt;argLine set to -javaagent:...jacoco...&lt;/code&gt; with no tracking agent in it, and no records were written.)&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix: give JaCoCo its own property
&lt;/h3&gt;

&lt;p&gt;Setup D separates the two concerns. JaCoCo writes to its own property, and your Surefire &lt;code&gt;argLine&lt;/code&gt; lists it explicitly next to whatever &lt;code&gt;-DargLine&lt;/code&gt; the build was given:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;properties&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- default so ${argLine} resolves in a normal build --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;argLine&amp;gt;&amp;lt;/argLine&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/properties&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;build&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;plugins&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.jacoco&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;jacoco-maven-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;0.8.13&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;executions&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;goals&amp;gt;&amp;lt;goal&amp;gt;&lt;/span&gt;prepare-agent&lt;span class="nt"&gt;&amp;lt;/goal&amp;gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;propertyName&amp;gt;&lt;/span&gt;jacocoArgLine&lt;span class="nt"&gt;&amp;lt;/propertyName&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;report&lt;span class="nt"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;verify&lt;span class="nt"&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;goals&amp;gt;&amp;lt;goal&amp;gt;&lt;/span&gt;report&lt;span class="nt"&gt;&amp;lt;/goal&amp;gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/executions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;maven-surefire-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;3.5.2&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;argLine&amp;gt;&lt;/span&gt;@{jacocoArgLine} ${argLine} -Dcustom.flag=on&lt;span class="nt"&gt;&amp;lt;/argLine&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/plugins&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/build&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a normal build &lt;code&gt;${argLine}&lt;/code&gt; is the empty default. In blastradius's tracking build it carries the tracking agent. JaCoCo's agent and the tracking agent both end up in the fork. If you do not set a custom &lt;code&gt;argLine&lt;/code&gt; at all (setup B), the default behavior already works and you need no change.&lt;/p&gt;

&lt;h2&gt;
  
  
  What coverage looks like on a pull request
&lt;/h2&gt;

&lt;p&gt;Here is the part to plan for. On a pull request, blastradius runs fewer tests, so JaCoCo reports coverage for fewer tests. The report is valid, not corrupted, but it only reflects what ran.&lt;/p&gt;

&lt;p&gt;I measured it on the fixture with a one-line change to &lt;code&gt;MathUtil&lt;/code&gt;, using setup D:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Run&lt;/th&gt;
&lt;th&gt;Tests run&lt;/th&gt;
&lt;th&gt;JaCoCo lines covered&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Full run on the PR (no blastradius)&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;6 / 6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;blastradius SELECT on the PR&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;1 / 6&lt;/strong&gt; (&lt;code&gt;MathUtil&lt;/code&gt; only)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The fixture is the extreme case, because each test touches only one class. Real suites overlap far more. But the principle holds in general:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Project-wide coverage percentages on a PR will drop&lt;/strong&gt; if you run selection on that build. A &lt;code&gt;jacoco:check&lt;/code&gt; rule with a project-wide threshold, evaluated on the PR build, can fail for a reason that has nothing to do with the change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coverage of the changed code is still meaningful&lt;/strong&gt;, because the tests that load a changed class are the ones that get selected. In the fixture, the changed class &lt;code&gt;MathUtil&lt;/code&gt; is fully covered. If you use a diff-coverage tool, point it at the changed lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Treat the base branch as the source of truth for overall coverage.&lt;/strong&gt; Publish your coverage badge and project-wide gates from the full-suite build on &lt;code&gt;main&lt;/code&gt; (the TRACK build is a full run), not from PRs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a team needs a project-wide coverage gate on every PR, that team should run the full suite for that gate and use selection only for the fast feedback build. That is a policy decision, not a limitation of the report.&lt;/p&gt;

&lt;h2&gt;
  
  
  A setup you can copy
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Use setup B (no explicit &lt;code&gt;argLine&lt;/code&gt;) or setup D above for JaCoCo.&lt;/li&gt;
&lt;li&gt;Add the plugin:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;   &lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.github.baokhang83.blastradius&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;blastradius-maven-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;0.4.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;executions&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;process-test-classes&lt;span class="nt"&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;goals&amp;gt;&amp;lt;goal&amp;gt;&lt;/span&gt;select&lt;span class="nt"&gt;&amp;lt;/goal&amp;gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/executions&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&amp;lt;baseRef&amp;gt;&lt;/span&gt;main&lt;span class="nt"&gt;&amp;lt;/baseRef&amp;gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;On &lt;code&gt;main&lt;/code&gt;, run your normal &lt;code&gt;mvn verify&lt;/code&gt;. The first run tracks and saves &lt;code&gt;.blastradius/&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Persist &lt;code&gt;.blastradius/&lt;/code&gt; with your CI cache between runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check that tracking succeeded&lt;/strong&gt;: look for &lt;code&gt;[blastradius] TRACK&lt;/code&gt; and the absence of &lt;code&gt;tracking failed&lt;/code&gt; in the log. A failure is silent as far as the build status goes.&lt;/li&gt;
&lt;li&gt;On pull requests, run the same command. Blastradius selects tests from the saved index.&lt;/li&gt;
&lt;li&gt;Keep a regular full-suite run (daily is the recommendation) as a safety net, since selection is sound by default but not guaranteed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why do test impact analysis tools conflict with JaCoCo?
&lt;/h3&gt;

&lt;p&gt;Both need a Java agent in the forked test JVM, and both usually set it through the &lt;code&gt;argLine&lt;/code&gt; property. If either overwrites the other's value, you lose one of the two. The collision is in how the property is written, not in the agents themselves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does blastradius change &lt;code&gt;argLine&lt;/code&gt; on pull requests?
&lt;/h3&gt;

&lt;p&gt;No. In SELECT mode it sets Surefire's &lt;code&gt;test&lt;/code&gt; filter (the same property as &lt;code&gt;-Dtest=&lt;/code&gt;), or &lt;code&gt;skipTests&lt;/code&gt; when nothing needs to run. It only adds a Java agent in the forked tracking build on the base branch.&lt;/p&gt;

&lt;h3&gt;
  
  
  My Maven build passes but PRs still run every test. Why?
&lt;/h3&gt;

&lt;p&gt;Check the base-branch log for &lt;code&gt;tracking failed&lt;/code&gt;. If your Surefire &lt;code&gt;&amp;lt;argLine&amp;gt;&lt;/code&gt; uses &lt;code&gt;@{argLine}&lt;/code&gt; with JaCoCo's default &lt;code&gt;prepare-agent&lt;/code&gt;, the tracking agent can be overwritten and no index is saved. Switching JaCoCo to its own &lt;code&gt;propertyName&lt;/code&gt; as shown above fixes it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Will my JaCoCo coverage report be correct on pull requests?
&lt;/h3&gt;

&lt;p&gt;It will be valid but partial: it reflects the tests that ran. Project-wide percentages drop when fewer tests run, while coverage of the changed code stays meaningful. Run overall coverage and any project-wide &lt;code&gt;jacoco:check&lt;/code&gt; gate on the base-branch full run.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does this work with Failsafe and integration tests?
&lt;/h3&gt;

&lt;p&gt;Selection narrows both Surefire and Failsafe. I only measured Surefire for this post, so check your integration-test setup with the same TRACK log check before relying on it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is selection safe?
&lt;/h3&gt;

&lt;p&gt;It is sound by default, not a guarantee. Reflection, generated code and string-dispatched APIs can escape dependency tracking, so keep a regular full-suite run as a backstop. The first post in this series has the replay numbers: &lt;a href="https://baokhang.hashnode.dev/how-we-cut-maven-junit5-test-runs-61-percent-apache-repos" rel="noopener noreferrer"&gt;61.4% fewer test executions across 800 commits, with the exclusions and caveats listed&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I am the author of blastradius.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>testing</category>
      <category>devops</category>
      <category>cicd</category>
    </item>
    <item>
      <title>Why Maven Build Cache Still Re-Runs Your Entire Test Suite on One-Line Edits</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Mon, 09 Nov 2026 08:50:01 +0000</pubDate>
      <link>https://dev.to/baokhang83/why-maven-build-cache-still-re-runs-your-entire-test-suite-on-one-line-edits-3ipb</link>
      <guid>https://dev.to/baokhang83/why-maven-build-cache-still-re-runs-your-entire-test-suite-on-one-line-edits-3ipb</guid>
      <description>&lt;p&gt;You install &lt;a href="https://maven.apache.org/extensions/maven-build-cache-extension/" rel="noopener noreferrer"&gt;&lt;code&gt;maven-build-cache-extension&lt;/code&gt;&lt;/a&gt;, your unchanged modules start restoring from cache in seconds, and PR builds feel fast. Then you edit one line in a utility class inside your biggest module and the build runs every test in that module again.&lt;/p&gt;

&lt;p&gt;That is not a bug in the cache. It is a granularity mismatch, and it is worth understanding precisely, because the two tools solve different halves of the problem and work well together.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the build cache does
&lt;/h2&gt;

&lt;p&gt;The extension fingerprints a module's inputs (sources, dependencies, plugin configuration) into a checksum. If it has seen that checksum before, it restores the module's outputs and skips the build. If it has not, it runs the module's whole lifecycle, Surefire included.&lt;/p&gt;

&lt;p&gt;So the cache's smallest unit is &lt;strong&gt;the module&lt;/strong&gt;. Anything inside it that changes, even a single character in one class, produces a new checksum for the module. There is no "mostly the same" in a checksum.&lt;/p&gt;

&lt;p&gt;For a repository with many small modules that is a great trade. For a repository with one large module (a monolith, a &lt;code&gt;core&lt;/code&gt; or &lt;code&gt;common&lt;/code&gt; module, a service with its tests in the same artifact), it means a one-line edit costs the module's entire test suite.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring it
&lt;/h2&gt;

&lt;p&gt;I built a small fixture rather than assert this. It is deliberately simple and synthetic, so read the numbers as an illustration of the mechanism, not a benchmark:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One Maven module, JDK 25 toolchain, Maven 3.9.12, &lt;code&gt;maven-build-cache-extension&lt;/code&gt; 1.2.0, Surefire 3.5.2, JUnit 5.10.2.&lt;/li&gt;
&lt;li&gt;Six small utility classes in &lt;code&gt;src/main&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;60 JUnit 5 test classes, 2 tests each: &lt;strong&gt;120 tests&lt;/strong&gt;. Each test class exercises exactly one utility class, so every utility has 10 test classes (20 tests) that depend on it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Steps and results:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;What changed&lt;/th&gt;
&lt;th&gt;Cache extension&lt;/th&gt;
&lt;th&gt;Tests run&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Base branch build&lt;/td&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;td&gt;miss (first build)&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rebuild, same inputs&lt;/td&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;hit&lt;/strong&gt;, module restored&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Branch A&lt;/td&gt;
&lt;td&gt;one line in &lt;code&gt;StringUtil&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;miss&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;120&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The unchanged rebuild is the cache doing its job. Branch A is the problem: &lt;code&gt;StringUtil&lt;/code&gt; is exercised by 20 of the 120 tests, and all 120 ran.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other half: which tests does this change actually reach?
&lt;/h2&gt;

&lt;p&gt;Narrowing inside the module needs information the cache does not have: which tests touch which production classes. &lt;a href="https://github.com/baokhang83/blastradius" rel="noopener noreferrer"&gt;blastradius&lt;/a&gt; gets it from the JVM instead of guessing from names or packages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Track.&lt;/strong&gt; On the base branch it runs the suite once with a &lt;code&gt;java.lang.instrument&lt;/code&gt; agent attached. Each time a class is loaded while a test runs, it records the pair (test, class). That gives a ground-truth map from every test to the production classes it loaded.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diff.&lt;/strong&gt; On a change branch it diffs the commit against the Git merge base to find the changed classes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Select.&lt;/strong&gt; A test is selected if one of its recorded classes changed, if the test is new or modified, if an executed class reaches a changed class through one or two recorded static invocation edges, or if a non-source change forces the conservative full-suite fallback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gate.&lt;/strong&gt; The selection becomes a standard Surefire/Failsafe &lt;code&gt;-Dtest=&lt;/code&gt; filter.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The same fixture, with blastradius added alongside the cache extension:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;What changed&lt;/th&gt;
&lt;th&gt;Cache extension&lt;/th&gt;
&lt;th&gt;Tests run&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Base branch build (tracking)&lt;/td&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;td&gt;miss&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Branch B&lt;/td&gt;
&lt;td&gt;one line in &lt;code&gt;MathUtil&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;miss&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;20 of 120&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rebuild branch B, same inputs&lt;/td&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;hit&lt;/strong&gt;, module restored&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The cache still misses, because the module's checksum changed. That is correct, and blastradius does not try to change it. What changes is what the missed build runs: only the 20 tests, from the 10 classes whose recorded dependencies include &lt;code&gt;MathUtil&lt;/code&gt;, instead of all 120 (83.3% skipped in this fixture).&lt;/p&gt;

&lt;p&gt;The two are complementary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;cache&lt;/strong&gt; removes whole modules that did not change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;blastradius&lt;/strong&gt; removes tests inside the modules that did.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Is this just a toy result?
&lt;/h2&gt;

&lt;p&gt;The fixture is evenly partitioned on purpose, so a clean 20/120 is what you would expect. Real suites are messier: shared fixtures, base classes and widely used utilities make some changes reach many tests. That is why I would not quote the fixture number, and why the historical replay matters more.&lt;/p&gt;

&lt;p&gt;blastradius has been replayed over 800 consecutive commits on four open-source projects (apache/shenyu, apache/httpcomponents-client, jhy/jsoup, apache/commons-io). Across those replays, the tool selected 966,368 of 2,501,105 test executions: &lt;strong&gt;61.4% fewer&lt;/strong&gt;, with the per-project range running from 45.0% (jsoup) to 71.0% (shenyu). A module-level cache has to treat each of those commits that touches a module's sources as a full rerun of that module. The replay figures are counts of test executions, not wall-clock CI time, and the full methodology, exclusions and caveats are in the &lt;a href="https://baokhang.hashnode.dev/ow-we-cut-maven-junit5-test-runs-61-percent-apache-repos" rel="noopener noreferrer"&gt;first post in this series&lt;/a&gt; and in &lt;a href="https://github.com/baokhang83/blastradius/blob/main/HISTORICAL_REPLAY_ANALYSIS.md" rel="noopener noreferrer"&gt;HISTORICAL_REPLAY_ANALYSIS.md&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup notes for using both
&lt;/h2&gt;

&lt;p&gt;Two things I hit while building the fixture, so you do not have to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The base-branch (tracking) build must actually run the tests.&lt;/strong&gt; Blastradius records dependencies by running the suite in a forked Maven build. If the cache extension restores that build from cache, no tests execute, nothing is recorded, and blastradius reports &lt;code&gt;tracking failed; ... falling back to the full suite&lt;/code&gt;. That fallback is safe (you get a full run), but you get no index. The fix that worked for me was to disable the cache for the tracking build with &lt;code&gt;MAVEN_OPTS="-Dmaven.build.cache.enabled=false"&lt;/code&gt;. Passing the flag only on the outer command line did not reach the forked build.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persist the &lt;code&gt;.blastradius/&lt;/code&gt; directory between runs&lt;/strong&gt;, the same way you persist the cache. On a change branch, blastradius needs the saved index from the base branch; without one it runs the full suite.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example plugin configuration, as used in the fixture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.github.baokhang83.blastradius&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;blastradius-maven-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;0.4.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;executions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;process-test-classes&lt;span class="nt"&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;goals&amp;gt;&amp;lt;goal&amp;gt;&lt;/span&gt;select&lt;span class="nt"&gt;&amp;lt;/goal&amp;gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/executions&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&amp;lt;baseRef&amp;gt;&lt;/span&gt;main&lt;span class="nt"&gt;&amp;lt;/baseRef&amp;gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where this does not help
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modules that are already small.&lt;/strong&gt; If your tests are split across many modules and each module's tests are fast, the cache is already close to optimal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Changes that reach everything.&lt;/strong&gt; A change to a class loaded by every test selects nearly every test, and a build-file or resource change triggers the full-suite fallback by design.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code reached through reflection or string-dispatched APIs.&lt;/strong&gt; Selection is sound by default, not guaranteed. Selector engines, expression languages and query parsers are the known hard case (jsoup showed this in the replay and drove a fix), so keep a regular full-suite run, daily is the recommendation, as a backstop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why does Maven Build Cache re-run all tests after a one-line change?
&lt;/h3&gt;

&lt;p&gt;The extension caches at module granularity. Any change to a module's inputs produces a new checksum, so the module is rebuilt in full, including all of its Surefire tests. The cache has no record of which tests depend on which classes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can the Maven Build Cache Extension skip individual tests?
&lt;/h3&gt;

&lt;p&gt;Not by itself: it restores or rebuilds whole modules. To run only the tests a change can affect, you need per-test dependency information, which is what test impact analysis tools such as blastradius record.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does blastradius know which tests a class change affects?
&lt;/h3&gt;

&lt;p&gt;On the base branch a Java agent records every class each test loads at runtime. On a change branch, tests whose recorded classes include a changed class are selected, along with new or modified tests and a bounded set of tests that reach the changed class through one or two static invocation edges.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I have to choose between the cache and blastradius?
&lt;/h3&gt;

&lt;p&gt;No. The cache skips unchanged modules; blastradius narrows tests inside changed ones. One setup note: run the base-branch tracking build with the cache disabled, otherwise the restored build runs no tests and nothing is recorded.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is it safe to skip tests?
&lt;/h3&gt;

&lt;p&gt;Selection is sound by default but not a guarantee. Reflection, generated code and string-dispatched APIs can escape it. Run the full suite on a regular cadence as a safety net; the recommendation is daily.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does 83% fewer tests mean 83% faster builds?
&lt;/h3&gt;

&lt;p&gt;No. The fixture counts tests run, not time, and it is synthetic. Real savings depend on which tests are slow, fixed costs such as compilation and packaging, and how widely your changes reach.&lt;/p&gt;

&lt;h3&gt;
  
  
  What do I need to try it?
&lt;/h3&gt;

&lt;p&gt;Maven, JDK 21 or later, a Git repository and JUnit 5. The plugin is on Maven Central as &lt;code&gt;io.github.baokhang83.blastradius:blastradius-maven-plugin&lt;/code&gt;. The fixture in this post is easy to recreate: six utility classes, 60 two-test classes with one per utility, and the two plugins configured as shown.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I am the author of blastradius.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>testing</category>
      <category>cicd</category>
    </item>
    <item>
      <title>How We Cut Maven &amp; JUnit 5 Test Runs by 61% Across Apache Repos Without Missing Regressions</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Mon, 09 Nov 2026 04:02:49 +0000</pubDate>
      <link>https://dev.to/baokhang83/how-we-cut-maven-junit-5-test-runs-by-61-across-apache-repos-without-missing-regressions-a3a</link>
      <guid>https://dev.to/baokhang83/how-we-cut-maven-junit-5-test-runs-by-61-across-apache-repos-without-missing-regressions-a3a</guid>
      <description>&lt;h1&gt;
  
  
  How We Cut Maven &amp;amp; JUnit 5 Test Runs by 61% Across Apache Repos Without Missing Regressions
&lt;/h1&gt;

&lt;p&gt;Most "predictive test selection" write-ups for Java come from vendors, and most of them give you a percentage with no way to check it. This one comes with the commit hashes. We replayed 800 consecutive commits from four open-source Java projects and counted what a dependency-based test selector would have run, what it would have skipped, and whether any skipped test would have caught a real bug.&lt;/p&gt;

&lt;p&gt;The tool is &lt;a href="https://github.com/baokhang83/blastradius" rel="noopener noreferrer"&gt;blastradius&lt;/a&gt;, an Apache-2.0 test impact analysis plugin for Maven (and Gradle) with JUnit 5. The headline: &lt;strong&gt;61.4% fewer test executions across the four replays, with 0 would-miss cases after the exclusions described below.&lt;/strong&gt; The rest of this post is about what those two numbers do and do not mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: record what tests actually load
&lt;/h2&gt;

&lt;p&gt;Test impact analysis (TIA) answers one question on a pull request: which tests could be affected by this diff? Static guesses (package names, module graphs) are cheap but loose. Blastradius records ground truth instead:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Track.&lt;/strong&gt; On a base-branch build, a &lt;code&gt;java.lang.instrument&lt;/code&gt; agent watches every class loaded while each test runs, and records which production classes each test really touched.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diff.&lt;/strong&gt; On a change branch, it diffs the commit against the Git merge base, so only the PR's own changes count, not whatever landed on &lt;code&gt;main&lt;/code&gt; after it diverged.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Select.&lt;/strong&gt; A test runs if one of its recorded dependencies changed, if it is new or modified, if an executed class reaches a changed class through one or two recorded static invocation edges, or if a non-source change (build files, resources) triggers the conservative "run everything" fallback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gate.&lt;/strong&gt; The selection narrows Surefire/Failsafe through the standard &lt;code&gt;-Dtest=&lt;/code&gt; filter, so it keeps working with JaCoCo and custom &lt;code&gt;argLine&lt;/code&gt; setups.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Missing or unusable baseline data always means a full run.&lt;/p&gt;

&lt;h2&gt;
  
  
  The experiment
&lt;/h2&gt;

&lt;p&gt;For each project, the validation harness replays &lt;strong&gt;200 consecutive commits&lt;/strong&gt;, treating each commit as the change it introduced over the one before it. For every pair it asks the selector what it would run, then compares against ground truth. A &lt;strong&gt;would-miss&lt;/strong&gt; is a test that caught a real regression or an injected mutant but that selection chose not to run. That is the failure that matters.&lt;/p&gt;

&lt;p&gt;On the same window, the harness also runs &lt;strong&gt;bounded mutation validation&lt;/strong&gt;: it injects synthetic faults into the head commit and checks whether the selected tests catch them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results: test executions skipped
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Project&lt;/th&gt;
&lt;th&gt;Commit range&lt;/th&gt;
&lt;th&gt;Pairs (excluded)&lt;/th&gt;
&lt;th&gt;Would-miss&lt;/th&gt;
&lt;th&gt;Selected / full&lt;/th&gt;
&lt;th&gt;Skipped&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/apache/shenyu" rel="noopener noreferrer"&gt;apache/shenyu&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://github.com/apache/shenyu/commit/69cd1d5721647a60007584983d96fc94452a4f6b" rel="noopener noreferrer"&gt;&lt;code&gt;69cd1d5&lt;/code&gt;&lt;/a&gt; → &lt;a href="https://github.com/apache/shenyu/commit/3a411e017acfc47636e2bbfeb2958108d1f15a05" rel="noopener noreferrer"&gt;&lt;code&gt;3a411e0&lt;/code&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;200 (0)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;153,142 / 527,508&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;71.0%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/apache/httpcomponents-client" rel="noopener noreferrer"&gt;apache/httpcomponents-client&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://github.com/apache/httpcomponents-client/commit/ef34bfa8fd6f2f6181ba2e41051050ed877e56df" rel="noopener noreferrer"&gt;&lt;code&gt;ef34bfa&lt;/code&gt;&lt;/a&gt; → &lt;a href="https://github.com/apache/httpcomponents-client/commit/4dae8da4a365f639e42fea84822285f345be7755" rel="noopener noreferrer"&gt;&lt;code&gt;4dae8da&lt;/code&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;200 (12)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;180,198 / 443,593&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;59.4%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/jhy/jsoup" rel="noopener noreferrer"&gt;jhy/jsoup&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://github.com/jhy/jsoup/commit/b62e362d3945e86725c817101332b66277aff9e4" rel="noopener noreferrer"&gt;&lt;code&gt;b62e362&lt;/code&gt;&lt;/a&gt; → &lt;a href="https://github.com/jhy/jsoup/commit/9d2241ff467d03accbf902a650adc60513bf5c11" rel="noopener noreferrer"&gt;&lt;code&gt;9d2241f&lt;/code&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;200 (10)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;193,635 / 351,882&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;45.0%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://github.com/apache/commons-io" rel="noopener noreferrer"&gt;apache/commons-io&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://github.com/apache/commons-io/commit/d4032376f0103c3e31a884e2358b58978e183e5f" rel="noopener noreferrer"&gt;&lt;code&gt;d403237&lt;/code&gt;&lt;/a&gt; → &lt;a href="https://github.com/apache/commons-io/commit/ffd9ddae6e637c0be9ab63e3dfa5ca98f2230bc5" rel="noopener noreferrer"&gt;&lt;code&gt;ffd9dda&lt;/code&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;200 (12)&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;439,393 / 1,178,122&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;62.7%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;800 (34)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;966,368 / 2,501,105&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;61.4%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The 61.4% is the aggregate: 966,368 selected executions out of 2,501,105 in the full suites. Note what it is: &lt;strong&gt;a count of test executions in a replay, not measured CI wall-clock time.&lt;/strong&gt; Slow tests and fast tests count the same, and your savings will depend on where your slow tests sit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results: injected faults
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Project&lt;/th&gt;
&lt;th&gt;Mutants (compilable)&lt;/th&gt;
&lt;th&gt;Caught by the full suite&lt;/th&gt;
&lt;th&gt;Killing tests selected&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;shenyu&lt;/td&gt;
&lt;td&gt;872 (778)&lt;/td&gt;
&lt;td&gt;339&lt;/td&gt;
&lt;td&gt;943 / 943&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;httpcomponents-client&lt;/td&gt;
&lt;td&gt;916 (916)&lt;/td&gt;
&lt;td&gt;551&lt;/td&gt;
&lt;td&gt;75,380 / 75,380&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;jsoup&lt;/td&gt;
&lt;td&gt;940 (931)&lt;/td&gt;
&lt;td&gt;606&lt;/td&gt;
&lt;td&gt;53,300 / 53,300 (see below)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;commons-io&lt;/td&gt;
&lt;td&gt;901 (901)&lt;/td&gt;
&lt;td&gt;850&lt;/td&gt;
&lt;td&gt;30,637 / 31,648 (see below)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A "killing test" is one that passed on head, failed on the mutant, and stayed failed on confirmation. Those are the tests selection must not skip. Counts are per mutant, so a test that kills five mutants counts five times.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we excluded, and what did not come out clean
&lt;/h2&gt;

&lt;p&gt;A benchmark is only worth reading if the awkward parts are on the page. Here they are.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Excluded commit pairs (34 of 800).&lt;/strong&gt; Pairs the harness could not measure count neither for nor against selection. In httpcomponents-client, 11 of 12 hit the build timeout on a slow multi-module rebuild and 1 hit a Surefire report containing an XML-illegal character (since fixed). In jsoup, all 10 exceeded the 40-minute mutation-build timeout. In commons-io, 11 hit the mutation-validation timeout and 1 failed to build under the harness.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flaky tests were excluded from the verdict.&lt;/strong&gt; &lt;code&gt;HttpClientPluginConfigurationTest&lt;/code&gt; (shenyu) and &lt;code&gt;TestTlsHandshakeTimeout#testTimeout&lt;/code&gt; (httpcomponents-client, flaky under parallel build load) were removed. Excluding the second is what brings httpcomponents-client's would-miss to 0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;commons-io had an unresolved case.&lt;/strong&gt; A first recorded run showed a would-miss on &lt;code&gt;URIOriginTest#testGetInputStream&lt;/code&gt;, a test parameterized on a live network fixture. A plain &lt;code&gt;mvn clean test&lt;/code&gt; at that commit passed (6,376 tests, 0 failures), but the pair then failed to build under the harness and could not be root-caused. It is excluded, so the consolidated would-miss is 0, but that is "not a confirmed miss," not "proven clean."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;commons-io skipped 3.2% of killing executions.&lt;/strong&gt; 1,011 of 31,648 killing test executions were skipped, spread over 42 commit pairs on the diff-targeted or whole-tree-fallback path rather than dependency-match selection. Every one of the 850 killed mutants still had at least one killing test selected, so the gap is partial under-selection, not a blind spot. This figure is provisional.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;jsoup exposed a real gap, which we then fixed.&lt;/strong&gt; The first 200-pair run skipped 5,808 killing executions: 5,682 from 12 &lt;code&gt;QueryParser&lt;/code&gt; mutations and 126 from two &lt;code&gt;Normalizer&lt;/code&gt; mutations. jsoup's CSS selector engine is a string DSL, which is exactly where class-load tracking is weakest: a selector string reaches code that the test never loads directly. Adding a bounded two-hop static-invocation rule fixed it: targeted replays of all 14 mutation identities selected all 16,642 killing executions. Those were targeted replays, not a fresh full 200-pair rerun.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The lesson from jsoup generalizes. Reflection, string-dispatched APIs, generated code, and call paths deeper than two edges sit outside the evidence. If your project is built around selector engines, expression languages or query parsers, weigh that before adopting.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, "without missing regressions"?
&lt;/h2&gt;

&lt;p&gt;Within this window and these exclusions, blastradius had 0 would-miss cases across 800 commit pairs on four projects, and it selected a killing test for every mutant the full suites caught. That is the claim, and it is a measured one rather than a guarantee. We recommend running the full suite on a regular cadence (daily is the recommendation) as a safety net, so an occasional gap is caught within a day rather than never. Fast, sound-by-default selection on every build, backstopped by a full run, is the intended trust model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it on your project
&lt;/h2&gt;

&lt;p&gt;Add the plugin from Maven Central:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.github.baokhang83.blastradius&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;blastradius-maven-plugin&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;0.4.0&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;executions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;process-test-classes&lt;span class="nt"&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;goals&amp;gt;&amp;lt;goal&amp;gt;&lt;/span&gt;select&lt;span class="nt"&gt;&amp;lt;/goal&amp;gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/executions&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;configuration&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;baseRef&amp;gt;&lt;/span&gt;main&lt;span class="nt"&gt;&amp;lt;/baseRef&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On your base branch it tracks; on other branches it selects. For separate CI runners, persist and restore the &lt;code&gt;.blastradius/&lt;/code&gt; directory with your CI cache.&lt;/p&gt;

&lt;p&gt;If you would rather check the mechanism against your own history before changing CI, the &lt;a href="https://github.com/baokhang83/blastradius/tree/main/blastradius-validator" rel="noopener noreferrer"&gt;validator harness&lt;/a&gt; is the same shadow-mode tool that produced the numbers above: it replays your repository's commits, reports what would have been skipped, and flags would-miss cases without touching your build.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repository: &lt;a href="https://github.com/baokhang83/blastradius" rel="noopener noreferrer"&gt;github.com/baokhang83/blastradius&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Full methodology and footnotes: &lt;a href="https://github.com/baokhang83/blastradius/blob/main/HISTORICAL_REPLAY_ANALYSIS.md" rel="noopener noreferrer"&gt;HISTORICAL_REPLAY_ANALYSIS.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Maven guide: &lt;a href="https://github.com/baokhang83/blastradius/blob/main/docs/maven-junit5-test-impact-analysis.md" rel="noopener noreferrer"&gt;docs/maven-junit5-test-impact-analysis.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Maturity and trust model: &lt;a href="https://github.com/baokhang83/blastradius/blob/main/MATURITY.md" rel="noopener noreferrer"&gt;MATURITY.md&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is test impact analysis (predictive test selection) for Java?
&lt;/h3&gt;

&lt;p&gt;It is a way to run only the tests a change could affect, instead of the whole suite, on every pull request. Blastradius does it by recording which production classes each test loads on the base branch, then selecting the tests whose recorded dependencies overlap the diff.&lt;/p&gt;

&lt;h3&gt;
  
  
  How is this different from running tests by module or package?
&lt;/h3&gt;

&lt;p&gt;Module and package filters guess from project structure. Blastradius uses classes actually loaded at runtime during each test, so a test in one module that exercises code in another is still selected when that code changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it work with JaCoCo and custom &lt;code&gt;argLine&lt;/code&gt; settings?
&lt;/h3&gt;

&lt;p&gt;Yes. Selection works through the standard Surefire/Failsafe &lt;code&gt;-Dtest=&lt;/code&gt; filter, so it does not replace your test runner or conflict with JaCoCo or a custom &lt;code&gt;argLine&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens when it cannot decide safely?
&lt;/h3&gt;

&lt;p&gt;It runs everything. A missing or unusable baseline, or a non-source change such as a build file or resource, triggers the full-suite fallback. New and modified tests are always selected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I still need to run the full suite?
&lt;/h3&gt;

&lt;p&gt;Yes. Selection is sound by default, not guaranteed. We recommend a full-suite run on a regular cadence (daily) as a backstop, so any gap is caught within a day.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does 61.4% fewer test executions mean 61.4% faster CI?
&lt;/h3&gt;

&lt;p&gt;No. The figure counts test executions in a replay, not wall-clock time. Your speedup depends on where your slow tests fall, plus fixed costs such as compilation and startup. The tracking build on your base branch also runs the full suite once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where does it struggle?
&lt;/h3&gt;

&lt;p&gt;Code reached only through string-dispatched APIs, reflection or generated code, or through call paths deeper than two recorded edges, sits outside the evidence. jsoup's selector engine exposed exactly this in the replay. Projects built around query parsers, expression languages or selector DSLs should weigh it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it support Gradle and Kotlin?
&lt;/h3&gt;

&lt;p&gt;Kotlin in the conventional &lt;code&gt;src/main/kotlin&lt;/code&gt; and &lt;code&gt;src/test/kotlin&lt;/code&gt; layout is supported, with a full-suite fallback for Kotlin inline functions. The Gradle plugin is in the repository, but at the time of writing it is not yet published to the Gradle Plugin Portal. The Maven plugin is on Maven Central.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I run it on separate CI runners?
&lt;/h3&gt;

&lt;p&gt;Yes. Persist and restore the &lt;code&gt;.blastradius/&lt;/code&gt; directory with your CI cache. An S3-compatible shared index store is available as an option if that suits your runners better.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I check it against my own repository before adopting it?
&lt;/h3&gt;

&lt;p&gt;Yes. The validator harness replays your own commit history in shadow mode, reports what would have been skipped, and flags would-miss cases without changing your build.&lt;/p&gt;

</description>
      <category>java</category>
      <category>cicd</category>
      <category>devops</category>
      <category>testing</category>
    </item>
    <item>
      <title>Why Kubernetes In-Place Memory Resize Gets Stuck "In Progress" on JVM Pods</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Sun, 08 Nov 2026 19:02:37 +0000</pubDate>
      <link>https://dev.to/baokhang83/why-kubernetes-in-place-memory-resize-gets-stuck-in-progress-on-jvm-pods-3j4l</link>
      <guid>https://dev.to/baokhang83/why-kubernetes-in-place-memory-resize-gets-stuck-in-progress-on-jvm-pods-3j4l</guid>
      <description>&lt;p&gt;You lowered a JVM pod's memory with an in-place resize, and the pod now shows &lt;code&gt;PodResizeInProgress&lt;/code&gt;, an &lt;code&gt;Error&lt;/code&gt; reason, and an old memory limit that never changes. The kubelet is not broken. It refuses to lower a memory limit below the container's current usage, and a JVM keeps its committed heap even after the objects in it are garbage. The resize completes as soon as the JVM gives the memory back, which I confirmed on a Kubernetes 1.35.8 cluster. Below are the real outputs, the fix, and how long it took.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short answer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cause:&lt;/strong&gt; the kubelet will not apply a memory-limit decrease while the container's current usage is above the new limit. A JVM's usage stays high after garbage collection because it keeps the heap committed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Symptom:&lt;/strong&gt; condition &lt;code&gt;PodResizeInProgress=True&lt;/code&gt; with reason &lt;code&gt;Error&lt;/code&gt;. &lt;code&gt;containerStatuses[].allocatedResources&lt;/code&gt; shows the new value, but &lt;code&gt;containerStatuses[].resources&lt;/code&gt; still shows the old one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It retries.&lt;/strong&gt; The kubelet retried about every 11 to 15 seconds. The pod was not OOM-killed and did not restart. The check protected the JVM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; make the JVM release memory, then let the resize finish. Releasing after the patch finished the resize on the next retry (about 20 s in my run). Releasing before the patch finished it 2 seconds after the patch, and the error never appeared.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;PodResizePending&lt;/code&gt; is a different problem.&lt;/strong&gt; I saw it only when I asked for more memory than the node has (&lt;code&gt;Infeasible&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What it looks like
&lt;/h2&gt;

&lt;p&gt;I ran a JVM pod on a single-node kind cluster, Kubernetes v1.35.8. The pod has Guaranteed QoS with a 900Mi memory request and limit. The JVM (Temurin 21, ZGC, &lt;code&gt;-Xmx600m&lt;/code&gt;) allocates 300 MB, holds it for 10 seconds, then drops all of it and idles. Inside the container, &lt;code&gt;memory.current&lt;/code&gt; read 417 MB.&lt;/p&gt;

&lt;p&gt;I shrank it to 300Mi through the &lt;code&gt;resize&lt;/code&gt; subresource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl patch pod jvm &lt;span class="nt"&gt;--subresource&lt;/span&gt; resize &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s1"&gt;'{"spec":{"containers":[{"name":"app","resources":{"requests":{"memory":"300Mi"},"limits":{"memory":"300Mi"}}}]}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few minutes later, &lt;code&gt;kubectl get pod jvm -o yaml&lt;/code&gt; (trimmed) showed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;conditions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;cannot&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;decrease&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;memory&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;limits:&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;[attempting&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;set&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;pod&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;memory&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;limit&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;(314572800)&lt;/span&gt;
      &lt;span class="s"&gt;below&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;current&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;usage&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;(435347456),&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;attempting&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;to&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;set&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;container&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;memory&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;limit&lt;/span&gt;
      &lt;span class="s"&gt;(314572800)&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;below&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;current&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;usage&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;(435347456)]'&lt;/span&gt;
    &lt;span class="na"&gt;observedGeneration&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
    &lt;span class="na"&gt;reason&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Error&lt;/span&gt;
    &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;True"&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;PodResizeInProgress&lt;/span&gt;
  &lt;span class="na"&gt;containerStatuses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;app&lt;/span&gt;
    &lt;span class="na"&gt;allocatedResources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;500m&lt;/span&gt;
      &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;300Mi&lt;/span&gt;        &lt;span class="c1"&gt;# what the kubelet accepted&lt;/span&gt;
    &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;500m&lt;/span&gt;
        &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;900Mi&lt;/span&gt;      &lt;span class="c1"&gt;# what is actually applied&lt;/span&gt;
    &lt;span class="na"&gt;restartCount&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At +10 s the condition was &lt;code&gt;PodResizeInProgress=True&lt;/code&gt; with no reason. By +31 s the reason was &lt;code&gt;Error&lt;/code&gt;. The cgroup never changed: &lt;code&gt;memory.max&lt;/code&gt; stayed at 900 MB, and &lt;code&gt;memory.current&lt;/code&gt; stayed at 417 MB for the whole minute I watched.&lt;/p&gt;

&lt;p&gt;The events show a repeating error, and the kubelet log says why:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Normal   ResizeStarted   Pod resize started: {... "memory":"300Mi" ... "generation":2}
Warning  ResizeError     Pod resize error: {... "error":"cannot decrease memory limits: [attempting to set pod memory limit (314572800) below current usage (435347456) ...]"}
Warning  ResizeError     (repeats)

kubelet: "Allocated pod resize is not currently feasible" err="cannot decrease memory limits: ..."
kubelet: ... ResizePodInPlaceError ... (retries at 18:50:18, :33, :47, :58, 18:51:13, :25)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That matches what the Kubernetes docs say: before decreasing a container's memory limit, if memory usage exceeds the requested limit, the resize is skipped and the status remains in an "In Progress" state. They call this best-effort because usage can spike right after the check. What the docs don't show is the &lt;code&gt;Error&lt;/code&gt; reason and the repeating &lt;code&gt;ResizeError&lt;/code&gt; events, which look alarming but are the kubelet waiting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a JVM does this
&lt;/h2&gt;

&lt;p&gt;The kubelet compares the container's current memory usage with the new limit. A JVM's usage is dominated by committed heap, and the JVM does not return committed heap just because the objects in it are gone.&lt;/p&gt;

&lt;p&gt;In my test the JVM sat idle for more than a minute with &lt;code&gt;ZUncommitDelay=1&lt;/code&gt; and gave nothing back. The likely reason is that no garbage-collection cycle ran after the data was dropped, so there was nothing to trigger an uncommit. I did not confirm that, and the behavior depends on the collector. Don't count on a JVM to release by itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;PodResizeInProgress&lt;/code&gt; vs &lt;code&gt;PodResizePending&lt;/code&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Condition&lt;/th&gt;
&lt;th&gt;What it means&lt;/th&gt;
&lt;th&gt;What I saw&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PodResizeInProgress&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The kubelet accepted the new resources and is applying them.&lt;/td&gt;
&lt;td&gt;With &lt;code&gt;Error&lt;/code&gt; and "below current usage", the kubelet is retrying a memory decrease.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PodResizePending&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The resize can't be started yet.&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;reason=Infeasible&lt;/code&gt;, message &lt;code&gt;Node didn't have enough capacity: memory, requested: 68719476736, capacity: 8321712128&lt;/code&gt;, when I asked for 64Gi on an 8 GB node.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you see &lt;code&gt;Infeasible&lt;/code&gt; or &lt;code&gt;Deferred&lt;/code&gt;, the problem is node capacity. If you see &lt;code&gt;InProgress&lt;/code&gt; plus "below current usage", the problem is the container's own memory, and the fix is below.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: release memory from inside the JVM
&lt;/h2&gt;

&lt;p&gt;On ZGC, lower the soft ceiling and force a collection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;exec &lt;/span&gt;jvm &lt;span class="nt"&gt;--&lt;/span&gt; jcmd 1 VM.set_flag SoftMaxHeapSize 104857600
kubectl &lt;span class="nb"&gt;exec &lt;/span&gt;jvm &lt;span class="nt"&gt;--&lt;/span&gt; jcmd 1 GC.run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Releasing while the resize was pending.&lt;/strong&gt; I ran the two commands against the stuck pod. &lt;code&gt;memory.current&lt;/code&gt; fell from 417 MB to 96 MB. The kubelet applied the resize on its next retry, 20 seconds after I started the release. &lt;code&gt;memory.max&lt;/code&gt; became 300 MB, &lt;code&gt;restartCount&lt;/code&gt; stayed 0, the condition cleared, and a &lt;code&gt;ResizeCompleted&lt;/code&gt; event appeared.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Releasing before the patch.&lt;/strong&gt; I recreated the pod, released first (424 MB → 101 MB), then patched. The resize applied 2 seconds after the patch. For this pod, the events were &lt;code&gt;ResizeStarted&lt;/code&gt; and &lt;code&gt;ResizeCompleted&lt;/code&gt; only. The &lt;code&gt;Error&lt;/code&gt; condition never appeared.&lt;/p&gt;

&lt;p&gt;Releasing first is cleaner: no error condition, no wait for a retry. But if you are already stuck, you don't need to re-patch. Free the memory and the kubelet finishes the job.&lt;/p&gt;

&lt;h2&gt;
  
  
  When it stays stuck
&lt;/h2&gt;

&lt;p&gt;The resize stays "In Progress" if the JVM can't get below the new limit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Live data is bigger than the new limit.&lt;/strong&gt; If the heap holds more live objects than the limit, I'd expect no collection to free enough, and the resize to stay pending. I didn't test this case. Pick a limit that fits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The ceiling is fixed.&lt;/strong&gt; &lt;code&gt;-Xmx&lt;/code&gt; can't change on a running JVM. The new limit must be above &lt;code&gt;-Xmx&lt;/code&gt; plus metaspace, code cache, thread stacks and direct buffers. If it isn't, you need a restart, which is what &lt;code&gt;resizePolicy: RestartContainer&lt;/code&gt; is for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory outside the heap.&lt;/strong&gt; &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; only moves the heap. Native memory and direct buffers stay.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A debugging checklist
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Which condition? InProgress or Pending, and the reason&lt;/span&gt;
kubectl get pod &amp;lt;pod&amp;gt; &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="nv"&gt;jsonpath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{range .status.conditions[?(@.type=="PodResizeInProgress")]}{.reason}: {.message}{"\n"}{end}'&lt;/span&gt;
kubectl get pod &amp;lt;pod&amp;gt; &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="nv"&gt;jsonpath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{range .status.conditions[?(@.type=="PodResizePending")]}{.reason}: {.message}{"\n"}{end}'&lt;/span&gt;

&lt;span class="c"&gt;# 2. What is accepted vs actually applied&lt;/span&gt;
kubectl get pod &amp;lt;pod&amp;gt; &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="nv"&gt;jsonpath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'allocated={.status.containerStatuses[0].allocatedResources.memory} applied={.status.containerStatuses[0].resources.limits.memory}{"\n"}'&lt;/span&gt;

&lt;span class="c"&gt;# 3. What the container is really using&lt;/span&gt;
kubectl &lt;span class="nb"&gt;exec&lt;/span&gt; &amp;lt;pod&amp;gt; &lt;span class="nt"&gt;--&lt;/span&gt; sh &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s1"&gt;'cat /sys/fs/cgroup/memory.current /sys/fs/cgroup/memory.max'&lt;/span&gt;

&lt;span class="c"&gt;# 4. The events&lt;/span&gt;
kubectl get events &lt;span class="nt"&gt;--field-selector&lt;/span&gt; involvedObject.name&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;pod&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;memory.current&lt;/code&gt; is above the new limit, the JVM is the thing to fix.&lt;/p&gt;

&lt;p&gt;One gotcha from my own test: use the default strategic merge patch, as in the command above. With &lt;code&gt;--type merge&lt;/code&gt;, the whole &lt;code&gt;containers&lt;/code&gt; list is replaced, and the API server rejects it with "resource requests cannot be removed".&lt;/p&gt;

&lt;h2&gt;
  
  
  What I didn't test
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Collectors other than ZGC in a cluster. I tested ZGC, Shenandoah and G1 in a container separately, in &lt;a href="https://baokhang.hashnode.dev/g1-release-memory-kubernetes-in-place-pod-resize" rel="noopener noreferrer"&gt;another article&lt;/a&gt;, but not through a kubelet.&lt;/li&gt;
&lt;li&gt;A multi-container pod, or any version other than v1.35.8.&lt;/li&gt;
&lt;li&gt;Whether the retry interval changes under load, or what happens if usage spikes right after the kubelet's check.&lt;/li&gt;
&lt;li&gt;How long a release takes on a large heap under real traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reproduce it
&lt;/h2&gt;

&lt;p&gt;You need Docker, &lt;code&gt;kind&lt;/code&gt; and &lt;code&gt;kubectl&lt;/code&gt;. &lt;code&gt;Hold.java&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Hold&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"allocated 300MB"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;clear&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"released refs"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;600000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pod.yaml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;jvm&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;app&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;eclipse-temurin:21-jdk&lt;/span&gt;
    &lt;span class="na"&gt;imagePullPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;IfNotPresent&lt;/span&gt;
    &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;java"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-XX:+UseZGC"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-XX:ZUncommitDelay=1"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-Xmx600m"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/w/Hold.java"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;volumeMounts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[{&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;w&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;mountPath&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;/w&lt;/span&gt;&lt;span class="pi"&gt;}]&lt;/span&gt;
    &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;500m&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;900Mi&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;   &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;500m&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;900Mi&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;resizePolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;resourceName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;restartPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;NotRequired&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;resourceName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;restartPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;NotRequired&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;w&lt;/span&gt;
    &lt;span class="na"&gt;configMap&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;hold&lt;/span&gt;&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kind create cluster &lt;span class="nt"&gt;--name&lt;/span&gt; resize-test &lt;span class="nt"&gt;--image&lt;/span&gt; kindest/node:v1.35.8
kubectl create configmap hold &lt;span class="nt"&gt;--from-file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Hold.java
kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; pod.yaml
kubectl &lt;span class="nb"&gt;wait&lt;/span&gt; &lt;span class="nt"&gt;--for&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;condition&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Ready pod/jvm &lt;span class="nt"&gt;--timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;240s
&lt;span class="c"&gt;# wait ~15 s until the JVM logs "released refs", then:&lt;/span&gt;
kubectl patch pod jvm &lt;span class="nt"&gt;--subresource&lt;/span&gt; resize &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s1"&gt;'{"spec":{"containers":[{"name":"app","resources":{"requests":{"memory":"300Mi"},"limits":{"memory":"300Mi"}}}]}}'&lt;/span&gt;
kubectl get pod jvm &lt;span class="nt"&gt;-o&lt;/span&gt; yaml        &lt;span class="c"&gt;# PodResizeInProgress, reason Error&lt;/span&gt;
kubectl &lt;span class="nb"&gt;exec &lt;/span&gt;jvm &lt;span class="nt"&gt;--&lt;/span&gt; jcmd 1 VM.set_flag SoftMaxHeapSize 104857600
kubectl &lt;span class="nb"&gt;exec &lt;/span&gt;jvm &lt;span class="nt"&gt;--&lt;/span&gt; jcmd 1 GC.run  &lt;span class="c"&gt;# the kubelet finishes on its next retry&lt;/span&gt;
kind delete cluster &lt;span class="nt"&gt;--name&lt;/span&gt; resize-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first image pull took about 90 seconds on my machine. The megabyte numbers will differ a little on yours.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why is my Kubernetes pod resize stuck in progress?
&lt;/h3&gt;

&lt;p&gt;The kubelet will not lower a memory limit below the container's current usage, and it keeps retrying. Check &lt;code&gt;kubectl get pod &amp;lt;pod&amp;gt; -o yaml&lt;/code&gt; for &lt;code&gt;PodResizeInProgress&lt;/code&gt; with a message saying "below current usage". Free memory inside the container and the resize finishes.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between PodResizePending and PodResizeInProgress?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;PodResizePending&lt;/code&gt; means the resize can't start yet. I saw it with &lt;code&gt;reason=Infeasible&lt;/code&gt; when the request exceeded the node's capacity. &lt;code&gt;PodResizeInProgress&lt;/code&gt; means the kubelet accepted the resize and is applying it. For a memory decrease it stays that way while usage is above the new limit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why won't the kubelet complete an in-place memory decrease for my Java pod?
&lt;/h3&gt;

&lt;p&gt;A JVM keeps its committed heap after garbage collection, so the container's usage stays above the new limit. On ZGC or Shenandoah, lower &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; and run &lt;code&gt;GC.run&lt;/code&gt;. On G1, use &lt;code&gt;GC.run&lt;/code&gt; or &lt;code&gt;G1PeriodicGCInterval&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Will the pod be OOM-killed while the resize is stuck?
&lt;/h3&gt;

&lt;p&gt;Not in my test. The pod kept running at 900Mi, with 0 restarts, until I freed memory. The Kubernetes docs say the check is best-effort, with no guarantees.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need to patch again after freeing memory?
&lt;/h3&gt;

&lt;p&gt;No. The kubelet retries on its own. In my run it completed 20 seconds after I released memory, with no new patch.&lt;/p&gt;

&lt;h3&gt;
  
  
  How long does the kubelet take to apply the resize after the JVM releases memory?
&lt;/h3&gt;

&lt;p&gt;20 seconds in the run where I released after the patch (the kubelet was retrying about every 11 to 15 seconds). If you release before the patch, it applied 2 seconds after.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Warden fits
&lt;/h2&gt;

&lt;p&gt;I maintain &lt;a href="https://github.com/baokhang83/mnemo-jvm-warden" rel="noopener noreferrer"&gt;mnemo-jvm-warden&lt;/a&gt;, an open-source Kubernetes controller and sidecar that does the release-then-resize order. The sidecar lowers the soft heap ceiling where the collector supports it, forces &lt;code&gt;GC.run&lt;/code&gt;, and checks that the process's resident memory dropped. Only then does the resize reach the kubelet. That order is the second case in this article, where the error never appears. I haven't tested that exact path in the cluster in this article.&lt;/p&gt;

&lt;p&gt;You don't need a tool for the fix: the two &lt;code&gt;jcmd&lt;/code&gt; commands above work on their own.&lt;/p&gt;

</description>
      <category>kubectl</category>
      <category>jvm</category>
      <category>java</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>Your G1 Pod Ignores SoftMaxHeapSize. Here's What Works Instead</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Sun, 08 Nov 2026 18:39:14 +0000</pubDate>
      <link>https://dev.to/baokhang83/your-g1-pod-ignores-softmaxheapsize-heres-what-works-instead-54k4</link>
      <guid>https://dev.to/baokhang83/your-g1-pod-ignores-softmaxheapsize-heres-what-works-instead-54k4</guid>
      <description>&lt;p&gt;G1GC vs. ZGC vs. Shenandoah for Kubernetes 1.35 In-Place Pod Resize&lt;/p&gt;

&lt;p&gt;When a pod shrinks in place, the JVM has to hand memory back to the operating system before the new limit applies. I tested how G1, ZGC and Shenandoah do that in a Linux container. All three released memory quickly in my test, but they differ in what triggers the release and in what &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; does. G1 accepts that flag and silently ignores it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short answer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ZGC and Shenandoah:&lt;/strong&gt; &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; works at runtime. Lower it, run &lt;code&gt;GC.run&lt;/code&gt;, and memory drops.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;G1:&lt;/strong&gt; &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; is accepted by &lt;code&gt;jcmd&lt;/code&gt; and has no effect. By default nothing returns memory. Two things did, in my test: an explicit &lt;code&gt;GC.run&lt;/code&gt;, and &lt;code&gt;G1PeriodicGCInterval&lt;/code&gt; set to a few seconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Release speed:&lt;/strong&gt; I measured no real difference. Each collector released a 300 MB working set within about 1 to 7 seconds. I did not measure large heaps or busy applications, which is where I'd expect differences, so treat "G1 is slower" as unproven.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The real G1 difference&lt;/strong&gt; is the missing ceiling. Nothing holds G1's heap below a target after you release, so you size &lt;code&gt;-Xmx&lt;/code&gt; for the peak and accept that it can grow back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lowering the limit first&lt;/strong&gt; killed all three (OOMKilled, exit 137). Release first, then resize.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What each collector gives you
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;ZGC&lt;/th&gt;
&lt;th&gt;Shenandoah&lt;/th&gt;
&lt;th&gt;G1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;SoftMaxHeapSize&lt;/code&gt; changes behavior&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;No&lt;/strong&gt; (flag accepted, no effect)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Returns memory by default&lt;/td&gt;
&lt;td&gt;After &lt;code&gt;ZUncommitDelay&lt;/code&gt; (300 s by default)&lt;/td&gt;
&lt;td&gt;After &lt;code&gt;ShenandoahUncommitDelay&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;No&lt;/strong&gt;, not without a trigger&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What triggers a release&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;SoftMaxHeapSize&lt;/code&gt; + &lt;code&gt;GC.run&lt;/code&gt;, or the uncommit delay&lt;/td&gt;
&lt;td&gt;Same&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;GC.run&lt;/code&gt;, or &lt;code&gt;G1PeriodicGCInterval&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pause cost of the trigger&lt;/td&gt;
&lt;td&gt;Not measured&lt;/td&gt;
&lt;td&gt;Not measured&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;GC.run&lt;/code&gt; is a full, stop-the-world GC. Not measured at scale.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The test
&lt;/h2&gt;

&lt;p&gt;The setup is the same as in my &lt;a href="https://baokhang.hashnode.dev/jvm-resizepolicy-restartcontainer-not-required-zgc-shenandoah" rel="noopener noreferrer"&gt;earlier test of &lt;code&gt;RestartContainer&lt;/code&gt;&lt;/a&gt;: Eclipse Temurin 21.0.13 in a Linux container on Docker Desktop, cgroup v2, and a small program that allocates and touches 300 MB, holds it for 10 seconds, then drops all of it and idles. &lt;code&gt;docker update --memory=300m&lt;/code&gt; lowers the cgroup limit on the running container in place. That is the kernel mechanism a pod resize uses, but there is no kubelet.&lt;/p&gt;

&lt;p&gt;For each collector, I ran two cases. &lt;strong&gt;Naive:&lt;/strong&gt; lower the limit straight away. &lt;strong&gt;Ordered:&lt;/strong&gt; set &lt;code&gt;SoftMaxHeapSize=100MB&lt;/code&gt;, run &lt;code&gt;GC.run&lt;/code&gt;, wait until &lt;code&gt;memory.current&lt;/code&gt; falls, then lower the limit.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Collector&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;memory.current&lt;/code&gt; before&lt;/th&gt;
&lt;th&gt;Naive: lower limit to 300 MB&lt;/th&gt;
&lt;th&gt;Ordered: release first, then lower&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ZGC (&lt;code&gt;-Xmx600m&lt;/code&gt;, limit 900 MB)&lt;/td&gt;
&lt;td&gt;403 MB&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;OOMKilled&lt;/strong&gt;, exit 137&lt;/td&gt;
&lt;td&gt;404 → &lt;strong&gt;89 MB&lt;/strong&gt; in 3 s, then &lt;strong&gt;still running&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shenandoah (&lt;code&gt;-Xmx500m&lt;/code&gt;, limit 700 MB)&lt;/td&gt;
&lt;td&gt;372 MB&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;OOMKilled&lt;/strong&gt;, exit 137&lt;/td&gt;
&lt;td&gt;361 → &lt;strong&gt;64 MB&lt;/strong&gt; in 1 s, then &lt;strong&gt;still running&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;G1 (&lt;code&gt;-Xmx600m&lt;/code&gt;, 4 MB regions, limit 900 MB)&lt;/td&gt;
&lt;td&gt;456 MB&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;OOMKilled&lt;/strong&gt;, exit 137&lt;/td&gt;
&lt;td&gt;463 → &lt;strong&gt;143 MB&lt;/strong&gt; in 2 s, then &lt;strong&gt;still running&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;G1 passes the ordered case, but I want to be exact about why. In that run I set &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; too, and it did nothing. The explicit &lt;code&gt;GC.run&lt;/code&gt; did the work.&lt;/p&gt;

&lt;h3&gt;
  
  
  What actually released memory on G1
&lt;/h3&gt;

&lt;p&gt;I tested each G1 lever on its own, starting from about 460 to 530 MB in use:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Lever on G1&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Nothing (default), wait 25 s&lt;/td&gt;
&lt;td&gt;459 → 459 MB. &lt;strong&gt;No release.&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;SoftMaxHeapSize=100MB&lt;/code&gt; only, wait 20 s&lt;/td&gt;
&lt;td&gt;535 → 535 MB. &lt;strong&gt;No effect.&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;GC.run&lt;/code&gt; only&lt;/td&gt;
&lt;td&gt;472 → &lt;strong&gt;150 MB&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;G1PeriodicGCInterval=3000&lt;/code&gt; set live, no &lt;code&gt;GC.run&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;518 → &lt;strong&gt;156 MB&lt;/strong&gt; in 7 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;SoftMaxHeapSize&lt;/code&gt; is listed as a manageable flag on G1 in JDK 21, so &lt;code&gt;jcmd VM.set_flag&lt;/code&gt; returns "Command executed successfully". That success message is misleading. Nothing in G1 reads the flag. If your automation sets the flag and then checks that the command succeeded, it will believe it lowered the ceiling on G1 when it did not.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to make G1 release memory back to the OS
&lt;/h2&gt;

&lt;p&gt;Pick one of these. I tested the first two.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run &lt;code&gt;GC.run&lt;/code&gt; from outside.&lt;/strong&gt; &lt;code&gt;jcmd &amp;lt;pid&amp;gt; GC.run&lt;/code&gt; triggers a full GC, after which G1 shrinks its heap. It is immediate, and it is a stop-the-world collection, so its pause grows with the live set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enable periodic GC.&lt;/strong&gt; &lt;code&gt;G1PeriodicGCInterval&lt;/code&gt; is a manageable flag, default &lt;code&gt;0&lt;/code&gt; (off). Set it at startup, or live: &lt;code&gt;jcmd &amp;lt;pid&amp;gt; VM.set_flag G1PeriodicGCInterval 3000&lt;/code&gt; (milliseconds). In my test, memory fell within 7 seconds on an idle JVM. A related flag, &lt;code&gt;G1PeriodicGCSystemLoadThreshold&lt;/code&gt;, is also manageable and, per JEP 346, can hold the periodic GC back while the system is busy. I did not test it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tune &lt;code&gt;MinHeapFreeRatio&lt;/code&gt; and &lt;code&gt;MaxHeapFreeRatio&lt;/code&gt;.&lt;/strong&gt; These are manageable and control how much free heap G1 keeps after a collection. I did not test them here.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What this means for in-place resize
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Release before you resize, on every collector.&lt;/strong&gt; The failure was identical across all three: lowering the limit while the JVM held committed memory got it killed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't trust "command succeeded" on G1.&lt;/strong&gt; Verify that &lt;code&gt;memory.current&lt;/code&gt; actually dropped, then resize. In Kubernetes, the kubelet's check also compares current usage to the new limit and holds the resize while usage is higher, although the docs say that check is best-effort.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plan the ceiling on G1.&lt;/strong&gt; With ZGC and Shenandoah, &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; keeps the heap near your target after release. On G1 nothing does, so a G1 heap that was just released can grow back toward &lt;code&gt;-Xmx&lt;/code&gt; before the limit drops. I did not test how fast. The practical rule is the one from my earlier article: the smallest limit must exceed &lt;code&gt;-Xmx&lt;/code&gt; plus non-heap memory, and on G1 you cannot rely on a soft ceiling to enforce it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mind the delay on ZGC.&lt;/strong&gt; &lt;code&gt;ZUncommitDelay&lt;/code&gt; defaults to 300 seconds. I shortened it to 1 second for the test. Without that, a ZGC release can take minutes unless you also lower the soft ceiling and wait for the uncommit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I didn't test
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Heap sizes above about 600 MB, live data that doesn't die, or JVMs under load. A full GC on G1 can cost far more at scale, and I haven't measured it.&lt;/li&gt;
&lt;li&gt;Whether G1 re-expands after release.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;G1PeriodicGCSystemLoadThreshold&lt;/code&gt;, &lt;code&gt;MinHeapFreeRatio&lt;/code&gt; and &lt;code&gt;MaxHeapFreeRatio&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A real kubelet. I used &lt;code&gt;docker update&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;G1 with the default region size. I set 4 MB regions because my test allocates 1 MB arrays, which are "humongous" objects in G1's default configuration, and the first G1 run ran out of heap.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reproduce it
&lt;/h2&gt;

&lt;p&gt;You need Docker. Save the files below in an empty folder.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hold.java&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Hold&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"allocated 300MB"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;clear&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"released refs"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;600000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;run.sh&lt;/code&gt; runs the naive and ordered cases for any collector:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# usage: ./run.sh &amp;lt;naive|ordered&amp;gt; &amp;lt;jvm flags...&amp;gt;      (run from the folder containing Hold.java)&lt;/span&gt;
&lt;span class="c"&gt;# Example: LIM=900 XMX=600 ./run.sh ordered -XX:+UseZGC -XX:ZUncommitDelay=1&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;
&lt;span class="nv"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;warden-test
docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1
docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;:/w &lt;span class="nt"&gt;-w&lt;/span&gt; /w eclipse-temurin:21-jdk javac Hold.java
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="nt"&gt;--memory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;700&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;m &lt;span class="nt"&gt;--memory-swap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;700&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;m &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;:/w &lt;span class="nt"&gt;-w&lt;/span&gt; /w &lt;span class="se"&gt;\&lt;/span&gt;
  eclipse-temurin:21-jdk java &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-Xmx&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;500&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;m Hold &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 60&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;docker logs &lt;span class="nv"&gt;$n&lt;/span&gt; 2&amp;gt;&amp;amp;1 | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="s1"&gt;'released refs'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;2
mem&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; /sys/fs/cgroup/memory.current&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;1048576&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"memory.current after the app dropped its data: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$mode&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; ordered &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; jcmd 1 VM.set_flag SoftMaxHeapSize 104857600   &lt;span class="c"&gt;# 100 MB soft ceiling&lt;/span&gt;
  docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; jcmd 1 GC.run
  &lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 30&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt; 250 &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"memory.current after SoftMaxHeapSize + GC.run: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB"&lt;/span&gt;
&lt;span class="k"&gt;fi
&lt;/span&gt;docker update &lt;span class="nt"&gt;--memory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;300m &lt;span class="nt"&gt;--memory-swap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;300m &lt;span class="nv"&gt;$n&lt;/span&gt;        &lt;span class="c"&gt;# in-place cgroup change, no restart&lt;/span&gt;
&lt;span class="nb"&gt;sleep &lt;/span&gt;8
docker inspect &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s1"&gt;'running={{.State.Running}} OOMKilled={{.State.OOMKilled}} exit={{.State.ExitCode}}'&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt;
docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x run.sh
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;600 ./run.sh naive   &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseG1GC &lt;span class="nt"&gt;-XX&lt;/span&gt;:G1HeapRegionSize&lt;span class="o"&gt;=&lt;/span&gt;4m
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;600 ./run.sh ordered &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseG1GC &lt;span class="nt"&gt;-XX&lt;/span&gt;:G1HeapRegionSize&lt;span class="o"&gt;=&lt;/span&gt;4m
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;600 ./run.sh naive   &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseZGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:ZUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;600 ./run.sh ordered &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseZGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:ZUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;700 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;500 ./run.sh naive   &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseShenandoahGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UnlockExperimentalVMOptions &lt;span class="nt"&gt;-XX&lt;/span&gt;:ShenandoahUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1000
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;700 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;500 ./run.sh ordered &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseShenandoahGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UnlockExperimentalVMOptions &lt;span class="nt"&gt;-XX&lt;/span&gt;:ShenandoahUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;g1-probe.sh&lt;/code&gt; tests each G1 lever on its own:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Which G1 lever actually returns memory? Run from the folder containing Hold.java.&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;
docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;:/w &lt;span class="nt"&gt;-w&lt;/span&gt; /w eclipse-temurin:21-jdk javac Hold.java
start&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1
  docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="nt"&gt;--memory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900m &lt;span class="nt"&gt;--memory-swap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900m &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;:/w &lt;span class="nt"&gt;-w&lt;/span&gt; /w eclipse-temurin:21-jdk &lt;span class="se"&gt;\&lt;/span&gt;
    java &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseG1GC &lt;span class="nt"&gt;-XX&lt;/span&gt;:G1HeapRegionSize&lt;span class="o"&gt;=&lt;/span&gt;4m &lt;span class="nt"&gt;-Xmx600m&lt;/span&gt; Hold &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
  &lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 60&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;docker logs &lt;span class="nv"&gt;$1&lt;/span&gt; 2&amp;gt;&amp;amp;1 | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="s1"&gt;'released refs'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;2&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
mem&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; /sys/fs/cgroup/memory.current&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;1048576&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"1) nothing (default), wait 25s"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;           start g1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;25&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"   &lt;/span&gt;&lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="s2"&gt; MB -&amp;gt; &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"2) SoftMaxHeapSize=100MB only, wait 20s"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  start g1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;g1 jcmd 1 VM.set_flag SoftMaxHeapSize 104857600 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;20&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"   &lt;/span&gt;&lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="s2"&gt; MB -&amp;gt; &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"3) GC.run only"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                           start g1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;g1 jcmd 1 GC.run &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;4&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"   &lt;/span&gt;&lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="s2"&gt; MB -&amp;gt; &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"4) G1PeriodicGCInterval=3000 set live"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    start g1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;
docker &lt;span class="nb"&gt;exec &lt;/span&gt;g1 jcmd 1 VM.set_flag G1PeriodicGCInterval 3000 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 40&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt; 250 &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"   &lt;/span&gt;&lt;span class="nv"&gt;$b&lt;/span&gt;&lt;span class="s2"&gt; MB -&amp;gt; &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem g1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB (after &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;s)"&lt;/span&gt;
docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; g1 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expect &lt;code&gt;OOMKilled=true exit=137&lt;/code&gt; for naive runs and &lt;code&gt;running=true&lt;/code&gt; for ordered ones. The megabyte numbers will differ a little on your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Which garbage collector is best for Kubernetes in-place pod resize?
&lt;/h3&gt;

&lt;p&gt;In my test, ZGC and Shenandoah are the easiest, because &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; changes their behavior and keeps the heap near a target. G1 also works if something triggers a release, but it has no soft ceiling. Pick the collector your latency requirements need first, and then use the matching release method.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I make G1 release memory back to the OS?
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;jcmd &amp;lt;pid&amp;gt; GC.run&lt;/code&gt;, or set &lt;code&gt;G1PeriodicGCInterval&lt;/code&gt; to a value in milliseconds (default &lt;code&gt;0&lt;/code&gt;, off). In my test both returned memory within a few seconds on a small idle heap.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; work with G1?
&lt;/h3&gt;

&lt;p&gt;No. &lt;code&gt;jcmd VM.set_flag SoftMaxHeapSize&lt;/code&gt; succeeds on G1 in JDK 21, but I saw no change in memory over 20 seconds, so I conclude G1 ignores it. It works on ZGC and Shenandoah.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why was my pod OOMKilled after an in-place memory decrease?
&lt;/h3&gt;

&lt;p&gt;The limit dropped while the JVM still held more committed memory than the new limit allows. In my test this killed the JVM on G1, ZGC and Shenandoah every time. Release memory first, check the resident memory, then lower the limit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is &lt;code&gt;GC.run&lt;/code&gt; safe to use in production?
&lt;/h3&gt;

&lt;p&gt;It triggers a full collection. On G1 that is stop-the-world, and its pause grows with the live set. I only tested a 600 MB heap on an idle JVM, so measure the pause on your own heap before relying on it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I still need &lt;code&gt;RestartContainer&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Only if the heap ceiling has to move. See my &lt;a href="https://baokhang.hashnode.dev/jvm-resizepolicy-restartcontainer-not-required-zgc-shenandoah" rel="noopener noreferrer"&gt;earlier article on &lt;code&gt;RestartContainer&lt;/code&gt;&lt;/a&gt; for the case where it is and isn't required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Warden fits
&lt;/h2&gt;

&lt;p&gt;I maintain &lt;a href="https://github.com/baokhang83/mnemo-jvm-warden" rel="noopener noreferrer"&gt;mnemo-jvm-warden&lt;/a&gt;, an open-source Kubernetes controller and sidecar that does the release-then-resize order for you. From its code and docs, it adjusts to the collector like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Detection:&lt;/strong&gt; the agent reads the target's GC beans and records, per collector, whether a soft max and uncommit are supported. ZGC and Shenandoah support both. G1 supports uncommit only. Serial, Parallel and Epsilon are treated as unsupported, and the agent stays read-only for them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Release:&lt;/strong&gt; it sets &lt;code&gt;SoftMaxHeapSize&lt;/code&gt; only where the collector has it, so on G1 that step is skipped instead of being sent and ignored. It then forces &lt;code&gt;GC.run&lt;/code&gt; and polls the committed heap until it drops and holds steady. It checks the process's resident memory before it shrinks the pod.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boost on G1:&lt;/strong&gt; a G1 workload that wants a Boost lease must already launch with &lt;code&gt;-Xmx&lt;/code&gt; covering the largest &lt;code&gt;heapTarget&lt;/code&gt; it will request, because there is no soft ceiling to raise later. The agent rejects a heap target above the launch-time &lt;code&gt;-Xmx&lt;/code&gt; for every collector, and the Boost docs note that G1 has no live soft-max knob, so a G1 Boost only ever confirms that the allocation change landed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The conclusions above do not depend on any tool. The &lt;code&gt;jcmd&lt;/code&gt; commands work without it.&lt;/p&gt;

</description>
      <category>java</category>
      <category>jvm</category>
      <category>kubernetes</category>
      <category>performance</category>
    </item>
    <item>
      <title>Why Kubernetes 1.35 resizePolicy: RestartContainer Isn't Required for ZGC/Shenandoah</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Sun, 08 Nov 2026 17:51:08 +0000</pubDate>
      <link>https://dev.to/baokhang83/why-kubernetes-135-resizepolicy-restartcontainer-isnt-required-for-zgcshenandoah-1cgp</link>
      <guid>https://dev.to/baokhang83/why-kubernetes-135-resizepolicy-restartcontainer-isnt-required-for-zgcshenandoah-1cgp</guid>
      <description>&lt;h1&gt;
  
  
  Why Kubernetes 1.35 resizePolicy: RestartContainer Isn't Required for ZGC/Shenandoah
&lt;/h1&gt;

&lt;p&gt;A lot of current advice says to set &lt;code&gt;resizePolicy: RestartContainer&lt;/code&gt; for memory on every JVM container. For growing the heap ceiling, that advice is right. For shrinking and regrowing within a ceiling you chose at launch, I tested ZGC and Shenandoah in a Linux container and found a restart isn't needed, as long as the JVM releases memory before the limit drops.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Kubernetes 1.35 can change a running container's memory in place (the &lt;code&gt;pods/resize&lt;/code&gt; subresource is GA).&lt;/li&gt;
&lt;li&gt;A JVM fixes its maximum heap at startup. Raising the limit in place does not raise the heap. Two popular articles are right about this.&lt;/li&gt;
&lt;li&gt;That does &lt;strong&gt;not&lt;/strong&gt; mean every memory change needs a restart. Three different operations hide inside "resize memory", and only one of them requires it.&lt;/li&gt;
&lt;li&gt;On ZGC and Shenandoah you can lower and raise the heap's soft ceiling at runtime. In my test, releasing memory first let a container's limit drop from 900 MB (or 700 MB) to 300 MB with no restart. Lowering the limit first got the JVM OOM-killed every time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the advice says, and where it's right
&lt;/h2&gt;

&lt;p&gt;Rack2Cloud's &lt;a href="https://www.rack2cloud.com/vertical-pod-autoscaler-in-place-resize-production/" rel="noopener noreferrer"&gt;VPA in production article&lt;/a&gt; says: "&lt;code&gt;-Xmx&lt;/code&gt; is a startup parameter. The JVM reads it once at initialization and sets the maximum heap ceiling for the lifetime of the process." It concludes that &lt;code&gt;resizePolicy: RestartContainer&lt;/code&gt; for memory "is the correct setting for JVM services, not &lt;code&gt;NotRequired&lt;/code&gt;". Its &lt;a href="https://www.rack2cloud.com/kubernetes-1-35-in-place-pod-resize-production/" rel="noopener noreferrer"&gt;Kubernetes 1.35 article&lt;/a&gt; lists &lt;code&gt;RestartContainer&lt;/code&gt; as appropriate "for memory decreases on workloads where the allocator won't release memory without a restart".&lt;/p&gt;

&lt;p&gt;Shubham Chepe's &lt;a href="https://shubhamchepe.com/blog/kubernetes-in-place-pod-resize-java-jvm.html" rel="noopener noreferrer"&gt;post on the JVM and in-place resize&lt;/a&gt; gives the same prescription: "CPU &lt;code&gt;NotRequired&lt;/code&gt;, memory &lt;code&gt;RestartContainer&lt;/code&gt;". He explains why: "If you raise the memory limit in place, the heap ceiling doesn't grow." On shrinking he says it is "riskier still, since the JVM may already be using more than the new limit allows."&lt;/p&gt;

&lt;p&gt;Both are correct that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the heap ceiling comes from &lt;code&gt;-Xmx&lt;/code&gt; or &lt;code&gt;-XX:MaxRAMPercentage&lt;/code&gt; at launch, and&lt;/li&gt;
&lt;li&gt;a bigger cgroup limit does not make a running JVM use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you need the heap ceiling itself to move, you need a restart. This article doesn't dispute that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three operations, not one
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Needs a restart?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Grow &lt;strong&gt;beyond&lt;/strong&gt; the &lt;code&gt;-Xmx&lt;/code&gt; the JVM launched with&lt;/td&gt;
&lt;td&gt;Yes. The ceiling is fixed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Shrink&lt;/strong&gt; the container's memory&lt;/td&gt;
&lt;td&gt;Not on ZGC or Shenandoah, if the JVM releases memory first.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Grow &lt;strong&gt;back&lt;/strong&gt; up to the launch-time ceiling&lt;/td&gt;
&lt;td&gt;No. Raise the container limit, then raise the soft ceiling.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The advice treats all three as the first one. That is the right call if you size &lt;code&gt;-Xmx&lt;/code&gt; to today's limit. It is the wrong one if you set &lt;code&gt;-Xmx&lt;/code&gt; for the peak and treat memory &lt;em&gt;below&lt;/em&gt; that as adjustable.&lt;/p&gt;

&lt;p&gt;ZGC and Shenandoah make this possible because of &lt;code&gt;SoftMaxHeapSize&lt;/code&gt;, a manageable flag. You can change it on a running JVM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;jcmd &amp;lt;pid&amp;gt; VM.set_flag SoftMaxHeapSize &amp;lt;bytes&amp;gt;
jcmd &amp;lt;pid&amp;gt; GC.run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The collector tries to stay under the soft limit and uncommits what it frees. &lt;code&gt;-Xmx&lt;/code&gt; remains the hard ceiling.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test
&lt;/h2&gt;

&lt;p&gt;I wanted to see what actually happens, so I ran it. The setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eclipse Temurin 21.0.13 in a Linux container on Docker Desktop, on cgroup v2 (&lt;code&gt;/sys/fs/cgroup/memory.current&lt;/code&gt; was present).&lt;/li&gt;
&lt;li&gt;A small program that allocates and touches 300 MB, holds it for 10 seconds, then drops all references and idles.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;docker update --memory=300m --memory-swap=300m&lt;/code&gt; to lower the cgroup limit on the running container. This changes &lt;code&gt;memory.max&lt;/code&gt; in place, which is the same kernel mechanism a pod resize uses, but it is not the kubelet.&lt;/li&gt;
&lt;li&gt;Two runs per collector. &lt;strong&gt;Naive:&lt;/strong&gt; lower the limit straight away. &lt;strong&gt;Ordered:&lt;/strong&gt; set &lt;code&gt;SoftMaxHeapSize=100MB&lt;/code&gt;, run &lt;code&gt;GC.run&lt;/code&gt;, wait for &lt;code&gt;memory.current&lt;/code&gt; to fall, and only then lower the limit.&lt;/li&gt;
&lt;li&gt;Uncommit delays were shortened (&lt;code&gt;ZUncommitDelay=1&lt;/code&gt;, &lt;code&gt;ShenandoahUncommitDelay=1000&lt;/code&gt;) so the test finishes quickly. Defaults are longer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Results:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Collector&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;memory.current&lt;/code&gt; before&lt;/th&gt;
&lt;th&gt;Naive: lower limit to 300 MB&lt;/th&gt;
&lt;th&gt;Ordered: release first, then lower&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ZGC (&lt;code&gt;-Xmx600m&lt;/code&gt;, limit 900 MB)&lt;/td&gt;
&lt;td&gt;403 MB&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;OOMKilled&lt;/strong&gt;, exit 137&lt;/td&gt;
&lt;td&gt;404 → &lt;strong&gt;89 MB&lt;/strong&gt; in 3 s, then limit lowered: &lt;strong&gt;still running&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shenandoah (&lt;code&gt;-Xmx500m&lt;/code&gt;, limit 700 MB)&lt;/td&gt;
&lt;td&gt;372 MB&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;OOMKilled&lt;/strong&gt;, exit 137&lt;/td&gt;
&lt;td&gt;361 → &lt;strong&gt;64 MB&lt;/strong&gt; in 1 s, then limit lowered: &lt;strong&gt;still running&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;With the ordered sequence, &lt;code&gt;memory.max&lt;/code&gt; read back as 314572800 (300 MB) and the container never restarted.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the kubelet adds
&lt;/h2&gt;

&lt;p&gt;My test used Docker, so it had no kubelet. In a real cluster, the kubelet tries to avoid an OOM kill when a memory limit goes down: according to the Kubernetes docs, if current usage is above the requested limit, the resize is skipped and stays "In Progress". The docs call this best-effort, with no guarantee, and note a race where usage can spike right after the check.&lt;/p&gt;

&lt;p&gt;For a JVM, that has a practical consequence. Committed heap counts as memory in use even when most of it is free, so the resize usually sits pending until the JVM gives memory back. Releasing first is what gets usage under the new limit, so the kubelet applies the resize. The ordered sequence works with the kubelet's check, not against it.&lt;/p&gt;

&lt;h2&gt;
  
  
  When RestartContainer is still the right answer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You need the heap ceiling to change. &lt;code&gt;-Xmx&lt;/code&gt; is fixed per process.&lt;/li&gt;
&lt;li&gt;You run G1 and haven't enabled periodic GC. G1 has no soft ceiling and returns heap mainly at a full GC or concurrent cycle, so release is slower and less predictable. I didn't test it here.&lt;/li&gt;
&lt;li&gt;You can accept the restart. A restart discards compiled code, loaded classes, pools and caches, and a service with few replicas loses capacity while it warms up. If that is fine for you, &lt;code&gt;RestartContainer&lt;/code&gt; is simpler and needs no extra tooling.&lt;/li&gt;
&lt;li&gt;Your limit is already close to &lt;code&gt;-Xmx&lt;/code&gt; plus non-heap memory. Shrinking safely needs room: the smallest limit must exceed &lt;code&gt;-Xmx&lt;/code&gt; plus metaspace, code cache, thread stacks and direct buffers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What this test does not show
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is a synthetic program, not a production service, and I tested ZGC and Shenandoah on one JDK build.&lt;/li&gt;
&lt;li&gt;ZGC and Shenandoah used slightly different heap and limit sizes (600/900 MB and 500/700 MB). My first ZGC run at 500 MB ran out of heap while filling 300 MB, so I gave it more room.&lt;/li&gt;
&lt;li&gt;It was not run through a kubelet. The kubelet's check will change what you see on a real cluster.&lt;/li&gt;
&lt;li&gt;I haven't measured how long a release takes on a large heap under real load.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reproduce it
&lt;/h2&gt;

&lt;p&gt;You need Docker. Save the two files below in an empty folder.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hold.java&lt;/code&gt; allocates and touches 300 MB, holds it for 10 seconds, then drops it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.*&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Hold&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt; &lt;span class="nc"&gt;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fill&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"allocated 300MB"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;clear&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"released refs"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;flush&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;600000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;run.sh&lt;/code&gt; starts a container, optionally releases memory first, then lowers the cgroup limit in place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# usage: ./run.sh &amp;lt;naive|ordered&amp;gt; &amp;lt;jvm flags...&amp;gt;      (run from the folder containing Hold.java)&lt;/span&gt;
&lt;span class="c"&gt;# Example: LIM=900 XMX=600 ./run.sh ordered -XX:+UseZGC -XX:ZUncommitDelay=1&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;
&lt;span class="nv"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;warden-test
docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1
docker run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;:/w &lt;span class="nt"&gt;-w&lt;/span&gt; /w eclipse-temurin:21-jdk javac Hold.java
docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="nt"&gt;--memory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;700&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;m &lt;span class="nt"&gt;--memory-swap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;700&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;m &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$PWD&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;:/w &lt;span class="nt"&gt;-w&lt;/span&gt; /w &lt;span class="se"&gt;\&lt;/span&gt;
  eclipse-temurin:21-jdk java &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-Xmx&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="k"&gt;:-&lt;/span&gt;&lt;span class="nv"&gt;500&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;m Hold &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 60&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;docker logs &lt;span class="nv"&gt;$n&lt;/span&gt; 2&amp;gt;&amp;amp;1 | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="s1"&gt;'released refs'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;2
mem&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; /sys/fs/cgroup/memory.current&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;1048576&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"memory.current after the app dropped its data: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$mode&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; ordered &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; jcmd 1 VM.set_flag SoftMaxHeapSize 104857600   &lt;span class="c"&gt;# 100 MB soft ceiling&lt;/span&gt;
  docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; jcmd 1 GC.run
  &lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 30&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt; 250 &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;sleep &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"memory.current after SoftMaxHeapSize + GC.run: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mem&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; MB"&lt;/span&gt;
&lt;span class="k"&gt;fi
&lt;/span&gt;docker update &lt;span class="nt"&gt;--memory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;300m &lt;span class="nt"&gt;--memory-swap&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;300m &lt;span class="nv"&gt;$n&lt;/span&gt;        &lt;span class="c"&gt;# in-place cgroup change, no restart&lt;/span&gt;
&lt;span class="nb"&gt;sleep &lt;/span&gt;8
docker inspect &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s1"&gt;'running={{.State.Running}} OOMKilled={{.State.OOMKilled}} exit={{.State.ExitCode}}'&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt;
docker &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;$n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the four cases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x run.sh
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;600 ./run.sh naive   &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseZGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:ZUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;900 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;600 ./run.sh ordered &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseZGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:ZUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;700 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;500 ./run.sh naive   &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseShenandoahGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UnlockExperimentalVMOptions &lt;span class="nt"&gt;-XX&lt;/span&gt;:ShenandoahUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1000
&lt;span class="nv"&gt;LIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;700 &lt;span class="nv"&gt;XMX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;500 ./run.sh ordered &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UseShenandoahGC &lt;span class="nt"&gt;-XX&lt;/span&gt;:+UnlockExperimentalVMOptions &lt;span class="nt"&gt;-XX&lt;/span&gt;:ShenandoahUncommitDelay&lt;span class="o"&gt;=&lt;/span&gt;1000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expect &lt;code&gt;OOMKilled=true exit=137&lt;/code&gt; for the naive runs and &lt;code&gt;running=true OOMKilled=false&lt;/code&gt; for the ordered ones. The exact megabyte numbers will differ a little on your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do I need &lt;code&gt;resizePolicy: RestartContainer&lt;/code&gt; for JVM memory?
&lt;/h3&gt;

&lt;p&gt;Only if the heap ceiling has to move. A JVM fixes its maximum heap at startup, so growing beyond the &lt;code&gt;-Xmx&lt;/code&gt; it launched with needs a restart. Shrinking, and growing back up to the launch ceiling, did not need one on ZGC or Shenandoah in my test, as long as the JVM released memory before the limit dropped.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why doesn't raising the container's memory limit give the JVM more heap?
&lt;/h3&gt;

&lt;p&gt;The JVM computes its maximum heap once, from &lt;code&gt;-Xmx&lt;/code&gt; or from &lt;code&gt;-XX:MaxRAMPercentage&lt;/code&gt; applied to the limit it saw at startup. A later in-place change to the cgroup limit does not change that number.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I change &lt;code&gt;-Xmx&lt;/code&gt; on a running JVM?
&lt;/h3&gt;

&lt;p&gt;No. What you can change on ZGC and Shenandoah is the soft ceiling, &lt;code&gt;SoftMaxHeapSize&lt;/code&gt;, which sits at or below &lt;code&gt;-Xmx&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What happens if I lower the memory limit without releasing memory first?
&lt;/h3&gt;

&lt;p&gt;In my test the JVM was OOM-killed (exit code 137) every time, on both ZGC and Shenandoah. On a real cluster the kubelet makes a best-effort attempt to avoid this and may keep the resize pending while usage is above the new limit. The Kubernetes docs say this check gives no guarantees, because usage can spike right after it.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I make a JVM give memory back without restarting it?
&lt;/h3&gt;

&lt;p&gt;On ZGC and Shenandoah, lower the soft ceiling and force a collection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;jcmd &amp;lt;pid&amp;gt; VM.set_flag SoftMaxHeapSize &amp;lt;bytes&amp;gt;
jcmd &amp;lt;pid&amp;gt; GC.run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then check that the process's resident memory dropped before you lower the limit. The collector's uncommit delay applies: I shortened it for the test, and the defaults are longer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does this work with G1?
&lt;/h3&gt;

&lt;p&gt;I didn't test it. G1 has no soft heap ceiling, so you cannot use the same flag. Plan for a slower, less predictable release, or use &lt;code&gt;RestartContainer&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the default &lt;code&gt;resizePolicy&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;NotRequired&lt;/code&gt; for both CPU and memory, which means the change is applied without restarting the container. Setting &lt;code&gt;RestartContainer&lt;/code&gt; for memory restarts the container, not the whole pod.&lt;/p&gt;

&lt;h3&gt;
  
  
  How small can the memory limit go?
&lt;/h3&gt;

&lt;p&gt;The smallest limit must stay above &lt;code&gt;-Xmx&lt;/code&gt; plus non-heap memory (metaspace, code cache, thread stacks, direct buffers) plus working-set headroom. For a typical Spring Boot service the non-heap part is commonly 100 to 150 MiB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where Warden fits
&lt;/h2&gt;

&lt;p&gt;I maintain &lt;a href="https://github.com/baokhang83/mnemo-jvm-warden" rel="noopener noreferrer"&gt;mnemo-jvm-warden&lt;/a&gt;, an open-source Kubernetes controller and sidecar that runs this order for you: lower the soft ceiling, force a GC, verify the process's resident memory dropped, and only then shrink the pod in place. To grow, it reverses the order. It does not change &lt;code&gt;-Xmx&lt;/code&gt;, so the same sizing rule applies. There is a &lt;a href="https://github.com/baokhang83/mnemo-jvm-warden/blob/main/docs/shrink-jvm-memory-kubernetes.md" rel="noopener noreferrer"&gt;guide&lt;/a&gt; with the full reasoning, and a &lt;a href="https://baokhang.hashnode.dev/shrink-jvm-memory-kubernetes-in-place-resize" rel="noopener noreferrer"&gt;walkthrough on a kind cluster&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The point of this article doesn't depend on any tool. The &lt;code&gt;jcmd&lt;/code&gt; commands above work without it.&lt;/p&gt;

</description>
      <category>java</category>
      <category>jvm</category>
      <category>kubernetes</category>
      <category>devops</category>
    </item>
    <item>
      <title>I built a workflow that forces AI agents to teach you the code they write</title>
      <dc:creator>BaoKhang</dc:creator>
      <pubDate>Sat, 18 Jul 2026 12:23:01 +0000</pubDate>
      <link>https://dev.to/baokhang83/i-built-a-workflow-that-forces-ai-agents-to-teach-you-the-code-they-write-3784</link>
      <guid>https://dev.to/baokhang83/i-built-a-workflow-that-forces-ai-agents-to-teach-you-the-code-they-write-3784</guid>
      <description>&lt;p&gt;As a developer, I got a bit scared and fed-up of blindly merging massive pull requests and losing context on my own codebase, so I built &lt;strong&gt;FluencyLoop&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/baokhang83/fluencyloop" rel="noopener noreferrer"&gt;https://github.com/baokhang83/fluencyloop&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is an open-source, local-first workflow plugin for &lt;strong&gt;Claude Code and Codex&lt;/strong&gt; that ensures your code and your codebase fluency are produced together.&lt;/p&gt;

&lt;p&gt;Instead of letting an agent dump raw code, it tracks your technical familiarity locally and pauses to explain complex architectural choices or rejected alternatives only on topics you do not know yet. It also produces documentation and tracks the decisions it makes along the way.&lt;/p&gt;

&lt;p&gt;Try it out ! It feels really good to get the AI caring for my understanding 🤣&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>learning</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
