Java Options and Arguments

Java Options and Arguments

Platform-managed Java servers automatically adjust their main memory settings according to the resources assigned to the container. These defaults can be changed when an application needs custom JVM options, memory limits, or startup arguments.
Custom Java servers: Java servers running inside custom Docker containers or VPS instances can be optimised in a similar way with the Java Memory Agent add-on.

Configure Java Options with variables.conf

The variables.conf file can be used to define the preferred Java options in one place. Its location depends on the application server:

  • Tomcat and TomEE: /opt/tomcat/conf/variables.conf
  • Jetty: /opt/jetty/etc/variables.conf
  • Spring Boot: /opt/shared/conf/variables.conf
  • GlassFish: /opt/glassfish/glassfish/domains/domain1/config/variables.conf
  • Payara: /opt/payara/glassfish/domains/domain1/config/variables.conf
  • WildFly: /opt/wildfly/conf/variables.conf
variables.conf file for Java options
Define custom Java options in the stack-specific variables.conf file.

Add the required options to the file, save the changes, and restart the application-server nodes.

Restart nodes button
Restart the nodes to apply the updated Java settings.

Redefine Main Java Parameters

Essential Java memory and garbage-collector parameters can also be redefined through dedicated container variables. Common examples include:

-Xms
-Xmn
-Xmx
-Xminf
-Xmaxf
-XX:MaxPermSize
-XX:+Use{GC}

For example, add the XMX variable to set the maximum Java heap size.

Java memory optimisation variable
Example of defining the maximum heap size through a container variable.

The platform also supports percentage-based RAM settings:

  • XMS_DEF_PERCENT — initial memory-allocation pool size as a percentage of the total available memory.
  • XMX_DEF_PERCENT — maximum memory-allocation pool size as a percentage of the total available memory.
Validation: When the calculated XMS value is larger than XMX, the platform automatically reduces XMS so that it equals XMX.

Spring Boot and Java Engine Specific Variables

Spring Boot and Java Engine templates provide two additional variables:

  • JAVA_OPTS — adds custom Java options for the application, similar to the variables.conf file.
  • JAVA_ARGS — passes custom arguments to the application’s main function.
Spring Boot Java options and arguments
JAVA_OPTS and JAVA_ARGS variables for Spring Boot and Java Engine.
Restart the application-server nodes after changing Java options or arguments.

What’s next?

  • Variables List
  • Environment Variables
  • Custom Environment Variables