diff --git a/vs/java/cgroup/CgroupConfigPrinter.java b/vs/java/cgroup/CgroupConfigPrinter.java index a7b0caf..dea57f0 100644 --- a/vs/java/cgroup/CgroupConfigPrinter.java +++ b/vs/java/cgroup/CgroupConfigPrinter.java @@ -1,3 +1,6 @@ +import java.lang.management.ManagementFactory; +import com.sun.management.OperatingSystemMXBean; + public class CgroupConfigPrinter { public static void main(String[] args) { int availableProcessors = Runtime.getRuntime().availableProcessors(); @@ -14,5 +17,13 @@ public static void main(String[] args) { System.out.println("Available Memory (Total): " + totalMemoryMB + " MB"); System.out.println("Available Memory (Free): " + freeMemoryMB + " MB"); System.out.println("Maximum Memory (Allocated): " + maxMemoryMB + " MB"); + + OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + + // deprecated in favor of getTotalMemorySize(), however new method is not avail on JDK8 + // keeps this so we can test against 8 and above + long totalSystemMemoryBytes = osBean.getTotalPhysicalMemorySize(); + long totalSystemMemoryMB = totalSystemMemoryBytes / (1024 * 1024); + System.out.println("Total System Memory: " + totalSystemMemoryMB + " MB"); } } diff --git a/vs/java/cgroup/application.jar b/vs/java/cgroup/application.jar index c29689d..35bdd87 100644 Binary files a/vs/java/cgroup/application.jar and b/vs/java/cgroup/application.jar differ diff --git a/vs/java/cgroup/runWithDocker.sh b/vs/java/cgroup/runWithDocker.sh index 3122a61..7ee2879 100755 --- a/vs/java/cgroup/runWithDocker.sh +++ b/vs/java/cgroup/runWithDocker.sh @@ -1 +1 @@ -docker run --rm --cpus=2 --memory=256m --name jvm_cgroup_demo_openjdk21 -v .:/app openjdk:21 java -Xmx256m -Xms256m -jar /app/application.jar +docker run --rm --cpus=2 --memory=512m --name jvm_cgroup_demo_openjdk21 -v .:/app openjdk:21 java -Xmx256m -Xms256m -jar /app/application.jar diff --git a/vs/java/cgroup/runWithDockerJ8.sh b/vs/java/cgroup/runWithDockerJ8.sh index e0ea056..8ec24d6 100755 --- a/vs/java/cgroup/runWithDockerJ8.sh +++ b/vs/java/cgroup/runWithDockerJ8.sh @@ -1,2 +1,2 @@ ## show that cgroup for CPU lim isn't respected -docker run --rm --cpus=2 --memory=256m --name jvm_cgroup_demo_openjdk8 -v .:/app openjdk:8 java -Xmx256m -Xms256m -jar /app/application.jar +docker run --rm --cpus=2 --memory=512m --name jvm_cgroup_demo_openjdk8 -v .:/app openjdk:8 java -Xmx256m -Xms256m -jar /app/application.jar