2

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
    Does this answer your question? [Setting -XX:MaxRam](https://stackoverflow.com/questions/52495429/setting-xxmaxram) – GotoFinal Mar 11 '20 at 17:08
  • Also check this: https://stackoverflow.com/questions/53451103/java-using-much-more-memory-than-heap-size-or-size-correctly-docker-memory-limi – GotoFinal Mar 11 '20 at 17:09

1 Answers1

3

-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.

apangin
  • 92,924
  • 10
  • 193
  • 247