问题
I run a java application with the following parameters:
#!/bin/bash
export JVM_OPTS="-XX:MaxRAM=150m"
export JVM_OPTS="$JVM_OPTS -XX:+UseSerialGC"
java $JVM_OPTS -jar application.jar
The htop shows:
- VIRT=475M
 - RES=238M
 - SHR=4880
 - MEM%=24.1
 
As I understand it, I need to look at the RES parameter. But in this case, it greatly exceeds -XX:MaxRAM. Expected that in this case, OutOfMemoryException will happen. What am I doing wrong? How to limit the memory of a java application for a container? Am I incorrectly looking at the used process memory?
I want to minimize the used RAM. OS - CentOS 7
回答1:
-XX:MaxRAM option affects nothing but the default heap size.
Memory used by a Java process (from the OS perspective) includes not only Java heap, but also many other things. See this answer for details.
来源:https://stackoverflow.com/questions/60636907/how-jvm-xxmaxram-option-can-be-correctly-used