Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Before JDK 10 the JVM ignored container limits; later it learned cgroup v1 and then cgroup v2, and the way CPU shares are used changed in later releases. What does this history teach about relying on runtime auto-detection in your infrastructure over the next decade?

The history teaches that runtime auto-detection always lags the infrastructure: the JVM learned about cgroup v1 years after containers were common and about cgroup v2 years after it existed, and even detection that works can change meaning between releases, as the use of CPU shares did. So we should rely on auto-detection only where we verify it. Infrastructure upgrades should be coupled with a minimum JDK version, CI should check what the JVM actually detects on the target platform, and the values that matter, such as the heap percentage, should be set explicitly so that a change in detection cannot silently resize our services.

Background to this question

Leadership questions about history are really questions about risk. The JVM's container story is a clear case study of a pattern that repeats across runtimes, libraries and platforms: software that tries to guess its environment works well until the environment changes, and then it fails quietly. A senior engineer is expected to turn that story into policy for the next ten years, when we will see new kernel features, new orchestrators and new runtimes. In this answer, we will walk through the history, draw the general lesson, and turn it into four practices: coupling infrastructure and JDK versions, testing detection in CI, setting key values explicitly, and deciding where auto-detection is still worth trusting.

1A Short History of the JVM and Containers

Docker made containers mainstream around 2014, but the JVM of that time read the host's memory and CPU count through ordinary operating system calls, which ignore cgroup limits. A JVM in a 2 GiB container on a 64 GB host sized its heap from 64 GB and its threads from all the host's cores. Teams added -Xmx and thread counts by hand or used scripts that parsed cgroup files at startup.

JDK 10 in 2018 introduced proper container support, later backported to JDK 8, and it read cgroup v1. Linux had already released cgroup v2 in 2016, and when distributions and Kubernetes switched to it by default, around 2021 and 2022, JVMs older than JDK 15 or without the backports went back to reading host values. Later, the treatment of CPU shares changed: older releases derived the processor count from the pod's CPU request when no limit was set, and later releases stopped doing that by default, so the same pod could report a different processor count after a JDK update. Check your version for the exact releases.

Detection gaps over time
PeriodInfrastructureJVM behaviour
Before 2018Docker and early Kubernetes, cgroup v1reads host values, ignores limits
JDK 10, later JDK 8 updatescgroup v1limits detected
cgroup v2 becomes defaultnew nodes and distributionsold JDKs read host values again
JDK 15, later 11 and 8 updatescgroup v2limits detected again
Later releasessame podsCPU shares no longer set processor count; check version
Each infrastructure step was followed by years in which some JVMs guessed wrong.

2The Lesson: Detection Lags, and It Changes Meaning

Two lessons come out of this. The first is the lag. A runtime can only detect what existed when it was written, and the fleet always contains runtimes that are several years old. So every new infrastructure feature starts with a period in which part of the fleet misreads it. The second lesson is quieter: even when detection works, its interpretation is a policy decision of the runtime maintainers, and policies change. The CPU shares change was reasonable, but a service that never set a processor count could see its thread pools resized after a routine JDK update.

Neither failure produces an error. The JVM starts happily with the wrong numbers, and we see the result as throttling, OOM kills or latency regressions, often blamed on something else. That is the real risk of auto-detection: not that it fails, but that it fails silently.

3Practice 1: Couple Infrastructure Upgrades With a Minimum JDK

A node or kernel change is also a runtime change for every service on it, so we plan them together. Before the platform moves to a new cgroup version, a new container runtime or a new node operating system, we define the minimum JDK release per vendor that handles it, inventory what every service runs, and block the migration of node pools until the services scheduled there meet the minimum. The inventory itself is a lasting asset: a daily report of JDK versions in production makes the next upgrade a query instead of an investigation.

4Practice 2: Verify Detection in CI on the Target Platform

We test what the JVM sees instead of assuming it. A CI job runs each base image on a node of the target type, with a known pod limit, and asserts on the detected values. The JVM already prints them for us.

Java
# CI job: pod limits memory=2Gi cpu=2 on the new node pool
java -XshowSettings:system -version 2>&1 | tee detected.txt
# Provider: cgroupv2
# Effective CPU Count: 2
# Memory Limit: 2.00G
grep -q 'Provider: cgroupv2' detected.txt || exit 1
grep -q 'Effective CPU Count: 2' detected.txt || exit 1
grep -q 'Memory Limit: 2.00G' detected.txt || exit 1
# for more detail when something looks wrong
java -Xlog:os+container=trace -version

The same job runs on every JDK upgrade and every node image change, so a change in detection shows up as a failed build rather than as a production incident. The exact output format can differ between releases, so the checks should be updated with the JDK, which is itself a useful prompt to read the release notes.

5Practice 3: Set the Values That Matter Explicitly

Some values are too important to leave to a guess. The heap percentage is the clearest: the default of 25 percent is rarely right for a dedicated service, and a change in how memory is detected would resize every heap in the fleet. Setting -XX:MaxRAMPercentage explicitly in the base image keeps the heap proportional to the limit while removing dependence on a default. For CPU, where we run without limits or where the processor count drives large thread pools, setting -XX:ActiveProcessorCount or configuring pool sizes from explicit configuration removes the dependence on shares or quotas.

The balance matters. We do not want to hard-code everything, because then every pod resize needs a flag change and we lose the benefits of the runtime's improvements. The rule is to be explicit about the values whose silent change would hurt, and to leave the rest to the runtime, with tests watching.

6Where Auto-Detection Still Earns Its Place

None of this means auto-detection is bad. For most of the fleet, most of the time, it gives sensible results and keeps configuration short. The point is to treat it like any other dependency: pin the version, test the behaviour, and know what happens when it changes. Over the next decade we can expect more of this, such as self-sizing heaps, new kernel interfaces and new orchestration models. The same approach applies to each: adopt detection where it is proven on our platform, verify it continuously, and keep an explicit override for the numbers that keep us safe.

As a leader, the work is mostly in making this routine: the inventory, the CI check, the base image values and the migration checklist belong to the platform team, so individual service teams get correct behaviour without having to learn the history themselves.

7Follow-up questions

Should we just set -Xmx everywhere to avoid all of this?

No. A fixed -Xmx avoids one detection problem but creates another: when the pod limit changes, the heap does not follow, and a lower limit causes OOM kills. A percentage keeps the heap tied to the limit while still being explicit about the share.

How do we know when the JVM changes how it detects resources?

Read the release notes of each JDK update, look for container and cgroup items, and let the CI detection check catch anything missed. A change in detected values on the same pod spec is the signal to investigate.

Does this lesson apply beyond the JVM?

Yes. Node.js, Go, Python libraries and databases all size thread pools or memory from detected resources, and each had similar container issues. The same practices, a minimum version, a detection test and explicit key values, apply to every runtime in the fleet.

8Conclusion

In this answer, we saw that the JVM ignored containers before JDK 10, then learned cgroup v1, lost track again when cgroup v2 became the default, and later changed how CPU shares affect the processor count. The lessons are that detection lags infrastructure and can change meaning without errors. So we couple infrastructure upgrades with a minimum JDK, verify detected values in CI on the target platform, set key values like the heap percentage explicitly, and trust auto-detection only where it is tested.

What to say in the interviewAbout 90 seconds aloud

Open with

The history shows two things. First, auto-detection lags the infrastructure. The JVM ignored container limits until JDK 10, learned cgroup v1 years after Docker was everywhere, and when cgroup v2 became the default on new nodes, every JVM older than 15 or without the backports quietly went back to reading the whole host.

Then, if they want more

Second, even working detection can change meaning: later releases stopped deriving the processor count from CPU shares, so the same pod could get different thread pools after a routine JDK update. And none of these failures produce an error. You see throttling, OOM kills or latency and blame something else. So I'd rely on auto-detection only where I verify it.

In practice that's four things. Couple every infrastructure change, like a new cgroup version or node image, with a minimum JDK version, backed by an inventory of what every service runs.

Run a CI check on the target node type that starts each base image with a known limit and asserts on -XshowSettings:system output, the provider, CPU count and memory limit. Set the values that would hurt if they silently changed, mainly MaxRAMPercentage, and ActiveProcessorCount where there are no CPU limits.

And leave the rest to the runtime, because hard-coding everything has its own failure mode. The same approach will apply to whatever comes next, like self-sizing heaps.

About this answer

Last updated
12 November 2026
Versions it names
Java 10, Java 15, Java 8
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Before JDK 10 the JVM ignored container limits; later it learned cgroup v1 and then...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/db6f86b80f/