Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker OpenJDK -Xmx or

Tags:

java

docker

jvm

I am trying to get a service running in a container, but ran into the OutOfMemoryError: Java heap space when the service in the container starts up (it does some memory intensive stuff).

I am trying to add the options for -Xmx1024 -Xms1024, but that didn't work.

I also attempted to use

-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap

as the OpenJDK Docker Hub documentation mentions, however when I run that, it fails with the following error:

Unrecognized VM option 'UnlockExperimentalVMOptions XX:+UseCGroupMemoryLimitForHeap'

The current Dockerfile that I am using looks like the following

FROM openjdk:8u131

...

...

CMD ["java","-XshowSettings:vm -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap","-jar", "target/my-jar.jar"]
like image 482
TheJediCowboy Avatar asked Apr 15 '26 02:04

TheJediCowboy


1 Answers

OpenJDK 10 and up detect the cgroup limit automatically without any additional flags (JDK-8146115). In addition they also let you specify the maximum heap size as fraction of that limit via the MaxRAMPercentage option (JDK-8186248).

like image 107
the8472 Avatar answered Apr 17 '26 14:04

the8472



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!