JavaExpertarticlePart 6 of 10 in Advanced Java Mastery

Cgroup Awareness in Java: Avoiding OOM Kills

Why does your Java app crash even when total RAM is available? Deep dive into container resource limits, cgroups, and JVM container awareness.

Sachin SarawgiApril 20, 20261 min read1 minute lesson

Cgroup Awareness in Java

If you limit your container to 1GB of RAM but don't configure your JVM correctly, the JVM will try to allocate as much as it sees on the host machine. The Linux kernel will then kill your container with an signal.

1. JVM Container Support

  • -XX:+UseContainerSupport: Enabled by default since Java 10. It forces the JVM to read the memory limit files.
  • -XX:MaxRAMPercentage: Don't set to a fixed value. Use to dynamically let the JVM take 75% of the container's RAM.

2. Monitoring

Always check inside your container to see exactly what the JVM sees.

Learning Path: Java Performance Mastery

Keep the momentum going

Step 6 of 6: Your next milestone in this track.

Next Article

NEXT UP

Hardware-Level False Sharing: Designing High-Speed Java Objects

2 min readAdvanced

Practical engineering notes

Get the next backend guide in your inbox

One useful note when a new deep dive is published: system design tradeoffs, Java production lessons, Kafka debugging, database patterns, and AI infrastructure.

No spam. Just practical notes you can use at work.

Sachin Sarawgi

Written by

Sachin Sarawgi

Engineering Manager and backend engineer with 10+ years building distributed systems across fintech, enterprise SaaS, and startups. CodeSprintPro is where I write practical guides on system design, Java, Kafka, databases, AI infrastructure, and production reliability.

Continue Series

Advanced Java Mastery

Lesson 6 of 10 in this learning sequence.

Next in series
1

Advanced

Java Heap Dump Analysis: A Step-by-Step Guide to Finding Memory Leaks

Java Heap Dump Analysis: Finding the Silent Killer An OutOfMemoryError (OOME) is the nightmare of every backend engineer. But the real problem isn't the error itself — it's the invisible memory leak that has been growing…

2

Advanced

Java Virtual Threads: High-Concurrency without the Complexity

Java Virtual Threads (Project Loom) Historically, Java used OS-level threads. Each thread cost ~1MB of memory for its stack. If you wanted 10,000 concurrent users, you needed 10GB of RAM just for the threads. Virtual Thr…

3

Advanced

HikariCP Tuning: Diagnosing Database Connection Pool Exhaustion

HikariCP Tuning: Mastering the Connection Pool In high-traffic Java applications, the Database Connection Pool (usually HikariCP) is often the silent bottleneck. If misconfigured, your app won't crash with an error; it w…

4

Expert

CPU Pipeline Stalls: Identifying Cache Misses in Java

CPU Pipeline Stalls: The Hidden Bottleneck When your Java code runs slower than expected, it is often because of "Stalls." The CPU pipeline flushes because it couldn't fetch data from the cache in time. 1. Cache Lines (6…

5

Advanced

Java Flight Recorder (JFR): Continuous Profiling with Zero Overhead

Java Flight Recorder (JFR): Your JVM's Black Box JFR is a profiling and event-collection framework built into the JVM. Unlike traditional profilers that add 10-20% overhead, JFR is designed for production use, typically…

6

Expert

Cgroup Awareness in Java: Avoiding OOM Kills

Cgroup Awareness in Java If you limit your container to 1GB of RAM but don't configure your JVM correctly, the JVM will try to allocate as much as it sees on the host machine. The Linux kernel will then kill your contain…

7

Advanced

Zero-Copy in Netty: The Backbone of High-Speed Java Networking

Zero-Copy in Netty: Mechanical Sympathy Netty is the engine behind almost every high-performance Java system (Kafka, Cassandra, Spring WebFlux). Its speed comes from its aggressive use of Zero-Copy techniques. 1. Bypassi…

8

Advanced

Hardware-Level False Sharing: Designing High-Speed Java Objects

Hardware-Level False Sharing in Java You’ve optimized your algorithms, but your high-throughput service is still stalling. The culprit might be invisible at the code level: False Sharing. 1. The CPU Cache Line Modern CPU…

9

Expert

Hardware-Level False Sharing: Designing High-Speed Java Objects

False Sharing: The Ghost in the Machine Multi-threaded Java code is often throttled not by the code, but by the CPU's memory architecture. 1. Cache Lines The CPU loads data from RAM in 64-byte chunks called Cache Lines.…

10

Expert

Hardware-Aware Programming: Optimizing for Modern CPUs

Hardware-Aware Programming In high-frequency environments, the efficiency of your code is dictated by the hardware. 1. NUMA Nodes Modern servers have multiple CPUs with local RAM (Non-Uniform Memory Access). If your thre…

Keep Learning

Move through the archive without losing the thread.

Related Articles

More deep dives chosen from shared tags, category overlap, and reading difficulty.

More in Java

Category-based suggestions if you want to stay in the same domain.