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
Feb 6
2024
Re-platforming Java applications using the updated AWS Serverless Java Container
Jun 24
2024
A library of HPC Applications Best Practices on AWS
Apr 10
2026
Building Memory-Intensive Apps with AWS Lambda Managed 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.