Quick revision
The short answer
JIT compilation runs on its own background threads that compete with request handling for the same CPU, and the JVM picks the number of compiler threads from the CPU count it sees. With a limit of 1 CPU there are very few compiler threads and they share one core with the application, so getting hot code through C1 and C2 takes minutes instead of seconds. We can allow more CPU or bursting during startup, use fewer but larger replicas, gate readiness until warmup is done, and use CDS or the AOT cache, which from JDK 25 can include method profiles.
What to remember
In this answer, we saw that the JIT compiles on background threads that share CPU with the application, and that the JVM sizes those threads and even picks the collector from the CPU count it sees. With one CPU, compilation and requests fight over a single throttled core, so warmup takes minutes. We can give more CPU during startup or use bigger replicas, keep traffic away until warmup is done, and reduce the work with CDS and the AOT cache, while avoiding TieredStopAtLevel=1 for long-running services.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
JIT compilation runs on its own background threads that compete with request handling for the same CPU, and the JVM picks the number of compiler threads from the CPU count it sees. With a limit of 1 CPU there are very few compiler threads and they share one core with the application, so getting hot code through C1 and C2 takes minutes instead of seconds. We can allow more CPU or bursting during startup, use fewer but larger replicas, gate readiness until warmup is done, and use CDS or the AOT cache, which from JDK 25 can include method profiles.
Why this question is asked
Many teams size Java pods by their steady-state CPU use, which is often low, and then wonder why new pods are slow. The answer lies in how much CPU the JVM needs in its first minutes, mostly for the JIT. Interviewers ask this to see whether we connect container settings to JVM internals. In this answer, we will recap what the JIT does during warmup, see how ergonomics react to the CPU count, work through why one CPU is so much slower than four, and then go through the options, including one that looks attractive but is wrong for services.
1A Quick Recap of Warmup and the JIT
A Java service starts running its code in the interpreter. Methods that are used a lot are compiled to native code by C1, with profiling, and the hottest are later recompiled by C2, which is much slower to compile but produces the fastest code. Steady-state throughput is reached only when the hot paths, often thousands of methods in a Spring application, have gone through C2.
This compilation happens on dedicated compiler threads, running alongside the application threads. A busy service at startup can easily use one or two full cores for compilation alone for a while.
2How Ergonomics Read the CPU Count
Ergonomics are the JVM's automatic choices based on the machine it finds. Since JDK 10 the JVM is container aware: it reads the CPU limit and memory limit of its cgroup and treats them as the machine's size. Several defaults follow from the CPU count.
Two things stand out. First, the compiler thread count is small and scales with CPUs. Second, with fewer than two CPUs the JVM does not consider the machine server class, so it picks Serial GC instead of G1. That is another surprise in a 1-CPU pod. More importantly, two compiler threads on one CPU can only run when the application threads let them, because the kernel shares that single core among all threads.
3Why One CPU Takes Minutes
With four CPUs, the compiler threads run on cores the application is not fully using during startup, so C1 and C2 work through their queues quickly, and hot code reaches level 4 within tens of seconds. With one CPU, every millisecond the compiler spends is a millisecond taken from request handling, and every busy moment of request handling delays compilation. The application is slow because its code is not compiled yet, so it uses more CPU per request, which leaves even less for the compiler. This feedback loop is why warmup stretches into minutes.
Container CPU limits make it worse. A limit of 1 CPU is enforced by the CFS quota, which gives the container 100 ms of CPU time per 100 ms period. If the JVM's threads use that up in the first 40 ms of a period, all of them, compiler and application, are throttled until the next period. Throttling shows up as latency spikes, and the container_cpu_cfs_throttled metrics make it visible.
| Measure | 1 CPU | 4 CPUs |
|---|---|---|
| Compiler threads | 2, sharing one core | 3, mostly on idle cores |
| Default collector | Serial | G1 |
| Time to steady throughput | about 4 minutes | under 1 minute |
| CPU throttling at startup | heavy | little |
4Options That Help
The direct fix is more CPU when the JVM needs it. If the platform allows it, we set a higher CPU limit than request, or no limit with a sensible request, so the pod can burst during startup. Some platforms can also resize CPU for a running pod, which allows a startup boost that is removed later; check what your Kubernetes version supports. Alternatively, we run fewer replicas with more CPU each, for example 5 pods with 4 CPUs instead of 20 pods with 1 CPU, which also gives the JIT and GC more room in steady state.
Second, we keep traffic away until the service is warm. A readiness probe that only reports ready after a warmup phase, in which the service runs representative requests against itself, means real users do not pay for compilation. Load balancers with slow start then ramp traffic gradually.
Third, we reduce the work to do. Class Data Sharing (CDS) stores parsed classes in an archive so startup skips much class loading. The AOT cache from Project Leyden builds on it: JDK 24 added ahead-of-time class loading and linking, and JDK 25 added method profiles to the cache and a simpler way to create it, so the JIT can start compiling with profiles from a training run instead of collecting them from scratch.
5The Tempting Option That Is Wrong for Services
-XX:TieredStopAtLevel=1 stops compilation at C1 without profiling. It cuts compiler CPU dramatically and makes startup fast, which is why it is popular for command-line tools, tests and short-lived functions. But a long-running service never gets C2 code, so its steady-state throughput can be considerably lower, often by a large margin on CPU-heavy paths. For a service that runs for days, paying a few minutes of warmup for permanently faster code is the right trade, and the options above reduce those minutes without giving up the peak.
6Follow-up questions
Should we set CICompilerCount higher in a 1-CPU pod?
Usually not. More compiler threads on one core do not create more CPU; they only compete harder with the application. The real constraint is CPU time, so the effective fixes are more CPU during startup, readiness gating and the AOT cache.
How can I tell that slow warmup is caused by the JIT?
Compare the compilation activity with throughput over time. JFR records compilation events and the time spent in them, and PrintCompilation shows how long hot methods take to reach level 4. If throughput reaches its plateau at about the same time the C2 queue drains, and container throttling is high during that period, the JIT is the bottleneck.
Does ActiveProcessorCount help?
-XX:ActiveProcessorCount tells the JVM to assume a given number of CPUs. Setting it to 2 in a 1-CPU pod changes ergonomics, for example G1 instead of Serial, but it does not add CPU time. It can be useful together with a CPU limit that allows bursting.
7Conclusion
In this answer, we saw that the JIT compiles on background threads that share CPU with the application, and that the JVM sizes those threads and even picks the collector from the CPU count it sees. With one CPU, compilation and requests fight over a single throttled core, so warmup takes minutes. We can give more CPU during startup or use bigger replicas, keep traffic away until warmup is done, and reduce the work with CDS and the AOT cache, while avoiding TieredStopAtLevel=1 for long-running services.
Open with
The JIT compiles on its own compiler threads, which run alongside the request threads. During warmup a Spring service has thousands of methods to get through C1 and then C2, and that needs real CPU, often a core or more for a while.
Then, if they want more
The JVM is container aware, so with a CPU limit of 1 it sizes things for one CPU: only two compiler threads, and it even chooses Serial GC because it is not a server-class machine. Those two threads share one core with request handling, and the CFS quota throttles the whole container when the quota is used up.
So compilation is slow, the code stays interpreted longer, each request costs more CPU, and that leaves even less for compilation. With four CPUs the compilers mostly run on idle cores and finish in under a minute. To fix it, I would allow bursting above the request during startup, or run fewer replicas with more CPU each.
I would gate readiness on a warmup phase so users do not pay for compilation, and use CDS or the AOT cache, which in JDK 25 can include method profiles from a training run.
I would not use TieredStopAtLevel=1 for a service, because it speeds startup but gives up C2 and lowers peak throughput for the whole life of the process.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25, Java 10, Java 24
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A Java service in a container with a CPU limit of 1 takes several minutes to reach...": https://scrivio-interview-library.netlify.app/java/jit-compilation/52a2b7620e/