Learnitweb

Improved Docker Container Integration with Java 10

1. Introduction

Java during startup normally queries the operating system to setup runtime defaults such as the number of GC threads and default memory limits. When running in a container, the operating functions used to get information provide information about the host and do not provide information about the container configuration and limits.

With the release of Java 10, the JVM now recognizes constraints set by container control groups (cgroups). In Java 10, the VM and core libraries were modified to first determine if the current running process is running in a container. The JVM has been modified to be aware that it is running in a Docker container and will extract container specific configuration information instead of querying the operating system.


The information being extracted is the number of CPUs and total memory that have been allocated to the container. The total number of CPUs available to the Java process is calculated from any specified cpu sets, cpu shares or cpu quotas.

2. Options to specify CPU and RAM percentage

This new improvement in Java 10 is available only for Linux based platforms and is enabled by default. It can be disabled in the command line with the JVM option:

-XX:-UseContainerSupport

In this new change, a JVM option is added to provide the ability to specify the number of CPUs that the JVM will use:

-XX:ActiveProcessorCount=count

This count overrides any other automatic CPU detection logic in the JVM.

Another change done is to allow more flexibility in selecting Heap % of available RAM. For this three new JVM options have been added to allow Docker container users to gain more fine grained control over the amount of system memory that will be used for Java Heap:

  • -XX:InitialRAMPercentage
  • -XX:MaxRAMPercentage
  • -XX:MinRAMPercentage

These options replace the deprecated Fraction forms XX:InitialRAMFraction, -XX:MaxRAMFraction, and -XX:MinRAMFraction.

3. Conclusion

In conclusion, harnessing the power of Docker containerization alongside Java 10 brings forth a formidable combination for modern software development. Through this tutorial, we’ve explored the enhanced Docker container integration with Java 10, leveraging its features for optimized performance, scalability, and flexibility.