JVM memory, CPU, and classpath best practices for Java containers on AWS
Containers Blog
This article explains how JVM interaction with container runtimes and host kernels can cause nondeterministic classpath resolution and resource allocation mismatches in Java applications running on Amazon ECS and Amazon EKS.
- Containers share the host kernel; classpath ordering depends on filesystem behavior and can change with host updates
- Use fat JARs or explicit classpath ordering to prevent nondeterministic class loading across deployments
- Modern JVMs (Java 10+) are container-aware and read cgroup limits; verify cgroups v2 support on older patch versions
- Use -XX:MaxRAMPercentage=75.0 to size heap automatically while leaving room for non-heap memory
- Use -XX:ActiveProcessorCount to pin CPU count explicitly and prevent thread overprovisioning on EC2
- Account for GC pauses in health check timing to avoid false restarts from CFS throttling
- On Fargate, CPU is proportional via shares; on EC2, CPU is hard-limited via CFS quota
Proper JVM configuration prevents silent failures in production and ensures reliable performance across container services and host updates.
The AWS News Feed is currently looking for gold sponsors. If you want to support the AWS community and reach a large audience of AWS professionals, consider sponsoring the AWS News Feed.
Related articles
The AWS News Feed is currently looking for silver sponsors. If you want to support the AWS community and reach a large audience of AWS professionals, consider sponsoring the AWS News Feed.