java JDK17 jvm parameter configuration
Configuration example
--add-opens=/=ALL-UNNAMED \ -Xms1500m -Xmx1500m \-XX:ReservedCodeCacheSize=256m \-XX:InitialCodeCacheSize=256m \ -XX:+UnlockExperimentalVMOptions \-XX:+UseZGC \-XX:ConcGCThreads=1 -XX:ParallelGCThreads=2 \-XX:ZCollectionInterval=30 -XX:ZAllocationSpikeTolerance=5 \-XX:+UnlockDiagnosticVMOptions -XX:-ZProactive \-Xlog:safepoint,classhisto*=trace,age*,gc*=info:file=/opt/gc-%:time,tid,tags:filecount=5,filesize=50m \-XX:+HeapDumpOnOutOfMemoryError \-XX:HeapDumpPath=/opt/
Parameter interpretation
These JVM parameters are used to configure the behavior of Java virtual machines (JVMs) to optimize performance, monitor garbage collection activities, manage memory allocations, and enable some experimental or diagnostic features.
Here is a detailed explanation of each parameter:
--add-opens=/=ALL-UNNAMED
- This parameter is used to open the module system
In the module
Access permissions to packages, allowing unnamed modules (usually classes that do not declare belonging to any module) to access elements within the package.
- This is necessary for certain frameworks or tools that require reflection access to the internal details of Java core libraries.
-Xms1500m -Xmx1500m
- Set the initial heap memory size of the JVM (
-Xms
) and maximum heap memory size (-Xmx
) is 1500MB. - This helps reduce memory allocation adjustments when the application starts and limits the maximum memory space it consumes.
-XX:ReservedCodeCacheSize=256m -XX:InitialCodeCacheSize=256m
- The initial size of the code cache and the maximum size reserved are set to 256MB respectively.
- Code cache is used to store local code compiled by JIT (Just-In-Time). These two settings ensure sufficient space for instant compilation to improve operational efficiency.
-XX:+UnlockExperimentalVMOptions
- Enable experimental JVM options
- Allows some features that are not yet stable or are not disclosed by default
-XX:+UseZGC
- Specify the use of Z Garbage Collector (ZGC)
- This is a scalable, low latency garbage collector, especially suitable for large-scale multi-core systems, designed to achieve the goal of pause time of no more than 10 milliseconds.
-XX:ConcGCThreads=1 -XX:ParallelGCThreads=2
- Configure the number of threads to ZGC or other parallel GC.
-
ConcGCThreads
=1 specifies the number of threads used in the concurrent marking phase, andParallelGCThreads
=2 specifies the number of threads to be used in the parallel recycling phase.
-XX:ZCollectionInterval=30 -XX:ZAllocationSpikeTolerance=5
- ZGC-specific parameters.
-
ZCollectionInterval
Set the time interval (in seconds) to trigger the garbage collection cycle. Here is to check whether garbage collection is required every 30 seconds. -
ZAllocationSpikeTolerance
Control the tolerance for sudden increase in memory allocation rate. The higher the value, the later the JVM responds to sudden increase in memory requirements to avoid unnecessary garbage collection.
-XX:+UnlockDiagnosticVMOptions -XX:-ZProactive
- The former unlocks diagnostic VM options, allowing for the use of some special options for debugging and diagnosis.
- The latter disables ZGC's active recycling mode, that is, does not perform garbage collection in advance based on predictions.
-Xlog:safepoint,classhisto*=trace,age*,gc*=info:file=/opt/gc-%:time,tid,tags:filecount=5,filesize=50m
- Configure logging, including security point activity, class loading statistics, age information, and all GC-related log levels set to trace and info respectively.
- The log will be written to
/opt/gc-%
,in%t
It will be replaced by the current timestamp, and a maximum of 5 files will be limited to retaining, each file will be up to 50MB, and it will contain time, thread ID and tag information.
-XX:+HeapDumpOnOutOfMemoryError
- When a memory overflow error occurs (OutOfMemoryError)
- Automatically create heap dump files, which is very useful for later analysis of the cause of the problem
-XX:HeapDumpPath=/opt/
- Specifies when memory overflow occurs
- The save path of the heap dump file is
/opt/
Overall:
These configurations are designed to optimize an application's memory management, garbage collection strategy, and improve the diagnostic capabilities when encountering memory problems, especially for application scenarios that require high-performance and low-latency processing.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.