1

I am using Java 11 on CentOS 7.x, because the server only have 2GB momory, Now I want to limit the max memory usage. I have tried this way:

nohup ${JAVA_HOME}/bin/java -Xmx256M -Xms128M -jar \
  -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=0.0.0.0:5019 \
  -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/apps/dolphin-post/ \
  ${APP_HOME}/${APP_NAME} >> ./cruise.log &

but the memory usage seems greater than 256MB(360MB+). This is the running status of the app(top -bcn1 -w512):

6059 root      20   0 2600460 364792  15280 S  0.0 19.4   0:51.38 /usr/local/jdk/bin/java -Xmx256M -Xms128M -jar -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=0.0.0.0:5019 /opt/apps/dolphin-post/libs/dolphin-post-service-1.0.0-SNAPSHOT.jar

is there any way to limit the java memory usage?

Dolphin
  • 29,069
  • 61
  • 260
  • 539
  • 2
    `-Xmx` only controls the size of the Java heap, not of other memory required by Java (Java itself, native memory allocation, etc). – Mark Rotteveel May 30 '21 at 07:04
  • is there any to limit the max memory usage of java process? @MarkRotteveel – Dolphin May 30 '21 at 07:05
  • 1
    Not that I'm aware of, look at [How to set the maximum memory usage for JVM?](https://stackoverflow.com/questions/1493913/how-to-set-the-maximum-memory-usage-for-jvm) (the accepted answer is definitely wrong, but some of the other answer provide partial solutions (e.g. specifying `-XX:MaxDirectMemorySize`), but there is no overall option. – Mark Rotteveel May 30 '21 at 07:12
  • The java memory usage is too much, my app is very simple with 3 controller but use 300MB+ memory, it take too much memory,I want just use 30MB or less to run the app.@Mark Rotteveel – Dolphin May 30 '21 at 08:37
  • 1
    Then why do you specify `-Xmx256M -Xms128M`? That by itself will causes the minimum heap size to be 128 MB. – Mark Rotteveel May 30 '21 at 09:02

0 Answers0