githubEdit

codeJava

Java record

1. Development Environment

Install

# ubuntu
apt install default-jdk
apt install openjdk-17-jdk

# macOS
brew install openjdk@21

# Manual install (Temurin / Adoptium)
wget https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21/OpenJDK21U-jdk_x64_linux_hotspot.tar.gz
tar xf OpenJDK21U-jdk_x64_linux_hotspot.tar.gz -C /usr/local/
export JAVA_HOME=/usr/local/jdk-21
export PATH=$JAVA_HOME/bin:$PATH

# Verify
java -version
javac -version

SDKMAN

A version manager for JDK and JVM-based tools (Maven, Gradle, etc.).

Install

Usage

IntelliJ IDEA

2. ProjectManage

Maven

Apache Maven is a build automation and dependency management tool for Java. It uses pom.xml to declare dependencies, plugins, and build lifecycle.

Install

Project Management

Configuration

Gradle

A build automation tool using Groovy/Kotlin DSL. It uses build.gradle (or build.gradle.kts) for project configuration.

Install

Project Management

3. JVM Settings

Common

JVM Container Parameters

Parameter
Description

-XX:+UseContainerSupport

Configures the JVM to detect the memory size and number of processors of the container it runs in, rather than detecting those of the entire operating system. The JVM uses the detected information for resource allocation. For example, the percentages set by -XX:InitialRAMPercentage and -XX:MaxRAMPercentage are calculated based on this information.

-XX:InitialRAMPercentage

Sets the initial percentage of container memory used by the JVM. It is recommended to keep this consistent with -XX:MaxRAMPercentage. The recommended value is 70.0, meaning the JVM initially uses 70% of container memory.

-XX:MaxRAMPercentage

Sets the maximum percentage of container memory used by the JVM. Due to system component overhead, it is recommended not to exceed 75.0. The recommended value is 70.0, meaning the JVM uses at most 70% of container memory.

-XX:+PrintGCDetails

Outputs detailed GC information.

-XX:+PrintGCDateStamps

Outputs GC timestamps in date format, e.g., 2019-12-24T21:53:59.234+0800.

-Xloggc:/home/admin/nas/gc-${POD_IP}-$(date '+%s').log

GC log file path. Ensure the container path where the log file resides already exists. It is recommended to mount this container path to a NAS directory or collect logs to SLS, to enable automatic directory creation and persistent log storage.

-XX:+HeapDumpOnOutOfMemoryError

Automatically generates a dump file when the JVM encounters an OOM error.

-XX:HeapDumpPath=/home/admin/nas/dump-${POD_IP}-$(date '+%s').hprof

Dump file path. Ensure the container path where the dump file resides already exists. It is recommended to mount this container path to a NAS directory, to enable automatic directory creation and persistent log storage.

[!NOTE] Note: Using the -XX:+UseContainerSupport parameter requires JDK 8u191+, JDK 10, or later versions. The -XX:+UseContainerSupport parameter is only supported on certain operating systems; please refer to the official documentation of your Java version for specific support details. In JDK 11 and later versions, the logging-related parameters -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, and -Xloggc:$LOG_PATH/gc.log have been deprecated. Please use -Xlog:gc:$LOG_PATH/gc.log instead. Dragonwell 11 does not support the ${POD_IP} variable. If you have not mounted the /home/admin/nas container path to a NAS directory, you must ensure that the directory exists before the application starts; otherwise, no log files will be generated.

JVM Heap Parameters

Parameter
Description

-Xms

Sets the initial JVM memory size. It is recommended to set this the same as -Xmx to avoid JVM memory reallocation after each garbage collection.

-Xmx

Sets the maximum available JVM memory size. To avoid container OOM, reserve sufficient memory for the system.

-XX:+PrintGCDetails

Outputs detailed GC information.

-XX:+PrintGCDateStamps

Outputs GC timestamps in date format, e.g., 2019-12-24T21:53:59.234+0800.

-Xloggc:/home/admin/nas/gc-${POD_IP}-$(date '+%s').log

GC log file path. Ensure the container path where the log file resides already exists. It is recommended to mount this container path to an NFS/NAS directory and collect logs to SLS, to enable automatic directory creation and persistent log storage.

-XX:+HeapDumpOnOutOfMemoryError

Automatically generates a dump file when the JVM encounters an OOM error.

-XX:HeapDumpPath=/home/admin/nas/dump-${POD_IP}-$(date '+%s').hprof

Dump file path. Ensure the container path where the dump file resides already exists. It is recommended to mount this container path to a NAS directory, to enable automatic directory creation and persistent log storage.

Memory Specification
JVM Heap Size

1GB

600 MB

2GB

1434 MB

3GB

2867 MB

4GB

5734 MB

[!NOTE] Memory specification parameter notes: In JDK 11 and later versions, the logging-related parameters -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, and -Xloggc:$LOG_PATH/gc.log have been deprecated. Please use -Xlog:gc:$LOG_PATH/gc.log instead. Dragonwell 11 does not support the ${POD_IP} variable. If you have not mounted the /home/admin/nas container path to a NAS directory, you must ensure that the directory exists before the application starts; otherwise, no log files will be generated.

Reference:

Last updated