Home icon

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.



Go to article

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

Jul 13
2026
Eliminating Java cold starts with AWS Lambda Managed Instances
Jul 31
2026
AWS Lambda now supports Java 8, 11, and 17 on Amazon Linux 2023
Aug 14
2026
Collecting CPU and memory metrics for AWS Lambda MicroVMs
Aug 5
2026
Resilient HPC and ML on AWS: Running Tightly Coupled Workloads on Spot Instances

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.