Java in a containermedium3-5 years

A service is deployed with `cpu: 500m` (half a core). Its `newFixedThreadPool(Runtime.getRuntime().availableProcessors())` ends up with exactly one thread, and throughput is much worse than expected. What is `availableProcessors()` actually returning here, and why?

A container's CPU limit isn't a count of cores, it's a quota — 500 millicores means 50 milliseconds of CPU time per 100-millisecond period, spread across however many physical cores the process happens to run on. A container-aware JVM reads that quota and reports it through Runtime.availableProcessors(), and a fractional quota below one whole core still rounds up to 1 — it never reports 0, since a process needs at least one logical processor to exist at all — so availableProcessors() returns exactly 1 here, and a thread pool sized from it gets exactly one thread. The fix isn't really about the thread pool at all: give the JVM at least one whole CPU if genuine parallelism (a parallelStream(), multiple worker threads doing CPU-bound work) matters, or size I/O-bound pools from the downstream's own capacity rather than from core count, since an I/O pool sized to 1 caps concurrent requests at one regardless of how much the JVM is actually waiting rather than computing.

The lesson behind it →
More on Java in a container