Inside Linux containers, OpenJDK versions 8 and later can correctly detect container-limited number of CPU cores and available RAM. In OpenJDK 11 this is turned on by default. In versions 8, 9, and 10 you have to enable the detection of container-limited amount of RAM using the following options"
In the section entitled "Make JVM respect CPU and RAM limits" in the description https://hub.docker.com/_/openjdk?tab=description, the information for Linux is out of date. It says:
As of JDK 8 v191 the settings discussed are obsolete, and the container detection is on by default https://www.oracle.com/technetwork/java/javase/8u191-relnotes-5032181.html#JDK-8146115