Talk about the support of the new JDK for docker containers



This article focuses on the support of the new JDK for docker containers.

Java8 and java9

Java 8u131 and above began to support Docker’s cpu and memory limitations.

cpu limit

That is, if -XX:ParalllelGCThreads or -XX:CICompilerCount is not explicitly specified, then the JVM uses docker’s cpu limit. If docker specifies cpu limit and jvm parameters also specify -XX:ParalllelGCThreads or -XX:CICompilerCount, the specified parameters shall prevail.

memory limit

In java8u131+ and java9, you need to add-xx:+unlock xperimental vmoptions-xx:+usecroupmemory limitorheap to make Xmx aware of docker’s memorylimit.

View parameter defaults

java -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal

Partial output

     bool UseCGroupMemoryLimitForHeap              = false                               {experimental} {default}

You can see that in java9, the UseCGroupMemoryLimitForHeap parameter is still experimental and is turned off by default.


     bool UseCGroupMemoryLimitForHeap              = false                               {experimental} {default}

Java10, UseCGroupMemoryLimitForHeap or experimental, but marked as obsolete.

However, java10 has introduced a new parameter

      int ActiveProcessorCount                     = -1                                       {product} {default}

ActiveProcessorCount can be used to specify the number of CPUs


Java11 officially removes UseCGroupMemoryLimitForHeap. For code changes, see8194086: Remove deprecated experimental flag UseCGroupMemoryLimitForHeap

At the same time, a new parameter is introduced

     bool UseContainerSupport                      = true                                     {product} {default}

UseContainerSupport defaults to true and details can be viewed using the -Xlog:os+container=trace parameter.
Even if container support is disabled using -XX:-UseContainerSupport, -XX:ActiveProcessorCount if specified, this parameter value will still be used.


Parameters/Version -XX:+UseCGroupMemoryLimitForHeap -XX:ActiveProcessorCount -XX:+UseContainerSupport
java9 Expected, default false No No
java10 Expected, default false -1 No
java11 remove -1 Product, default true