Table of Contents
Memory-related configuration
Garbage collector selection
Debugging and diagnostic related flags
Home Java javaTutorial What are common JVM flags?

What are common JVM flags?

Jul 03, 2025 am 02:12 AM

JVM flags are used to configure Java virtual machine behavior, mainly covering memory settings, garbage collector selection and debugging diagnosis. In terms of memory, -Xms sets the initial heap size, -Xmx sets the maximum heap size, -Xmn sets the young generation size, and reasonable configuration can avoid frequent GC or OOM. In terms of garbage collectors, UseSerialGC is suitable for small applications, UseParallelGC is suitable for throughput priority services, and UseG1GC is suitable for modern low-latency scenarios. Debugging related parameters such as PrintGCDetails printing GC logs, Xloggc output logs to files, HeapDumpOnOutOfMemoryError when generating OOM, agentlib or javaagent connection performance tools, which helps to analyze the problem. Mastering these commonly used flags can significantly improve the stability and performance of Java applications.

What are common JVM flags?

JVM flags (Java virtual machine parameters) are important options for configuring JVM behavior when starting Java programs. They can affect key aspects such as memory settings, garbage collection strategies, and performance tuning. For development and operation and maintenance personnel, it is very practical to master some commonly used JVM flags.

The default memory configuration of JVM often cannot meet the needs of actual applications, especially for scenarios where high concurrency or big data processing are performed. You can adjust the heap memory size by following common parameters:

  • -Xms : Set the initial heap size of the JVM. For example, -Xms512m means that the initial heap is 512MB.
  • -Xmx : Set the maximum heap size of JVM. For example, -Xmx2g means that the maximum heap is 2GB.
  • -Xmn : Set the size of the young generation. Appropriately increasing it can improve the allocation efficiency of object, but it will reduce the space of the elderly.

It is recommended to set these values ​​reasonably according to the application load to avoid frequent GC or OOM (Out Of Memory) errors. Usually, setting -Xms and -Xmx to the same value can reduce the overhead of dynamic adjustment.

Garbage collector selection

Different GC policies are suitable for different types of Java applications. Common GC flags are as follows:

  • -XX: UseSerialGC : Use serial GC, suitable for small applications or single-core machines.
  • -XX: UseParallelGC : ParallelGC, suitable for throughput-first services.
  • -XX: UseConcMarkSweepGC : CMS GC, focusing on low latency, but has been marked as abandoned after Java 8.
  • -XX: UseG1GC : G1 GC, a modern mainstream GC method, balancing throughput and latency.

If your application is sensitive to response time, such as web services, it is recommended to use G1GC; while batch tasks focus more on throughput, you can choose ParallelGC.

Debug class parameters can help you analyze the running JVM status:

  • -XX: PrintGCDetails and -XX: PrintGCDateStamps : Print detailed GC logs for easy subsequent analysis.
  • -Xloggc:<file-path></file-path> : Output the GC log to the specified file, for example -Xloggc:/var/log/app-gc.log .
  • -XX: HeapDumpOnOutOfMemoryError : Generates a heap dump file when OOM occurs, for subsequent analysis using tools (such as MAT).
  • -agentlib:jprofilerti or -javaagent:/path/to/your-agent.jar : Used to connect to performance analysis tools such as JProfiler or VisualVM.

This type of parameters is very useful when there is a problem with the production environment, but some will affect performance, so it is recommended to enable it only if needed.


Basically that's it. There are many types of JVM flags, but the above are the most common and practical parts. Understanding and rational use of them can significantly improve the stability and performance of Java applications.

The above is the detailed content of What are common JVM flags?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

How to add a JAR file to the classpath in Java? How to add a JAR file to the classpath in Java? Sep 21, 2025 am 05:09 AM

Use the -cp parameter to add the JAR to the classpath, so that the JVM can load its internal classes and resources, such as java-cplibrary.jarcom.example.Main, which supports multiple JARs separated by semicolons or colons, and can also be configured through CLASSPATH environment variables or MANIFEST.MF.

How to create a file in Java How to create a file in Java Sep 21, 2025 am 03:54 AM

UseFile.createNewFile()tocreateafileonlyifitdoesn’texist,avoidingoverwriting;2.PreferFiles.createFile()fromNIO.2formodern,safefilecreationthatfailsifthefileexists;3.UseFileWriterorPrintWriterwhencreatingandimmediatelywritingcontent,withFileWriterover

Building Extensible Applications with the Java Service Provider Interface (SPI) Building Extensible Applications with the Java Service Provider Interface (SPI) Sep 21, 2025 am 03:50 AM

JavaSPI is a built-in service discovery mechanism in JDK, and implements interface-oriented dynamic expansion through ServiceLoader. 1. Define the service interface and create a file with the full name of the interface under META-INF/services/, and write the fully qualified name of the implementation class; 2. Use ServiceLoader.load() to load the implementation class, and the JVM will automatically read the configuration and instantiate it; 3. The interface contract should be clarified during design, support priority and conditional loading, and provide default implementation; 4. Application scenarios include multi-payment channel access and plug-in verification; 5. Pay attention to performance, classpath, exception isolation, thread safety and version compatibility; 6. In Java9, provide can be used in combination with module systems.

A deep understanding of HTTP persistent connections: policies and practices for sending multiple requests on the same socket A deep understanding of HTTP persistent connections: policies and practices for sending multiple requests on the same socket Sep 21, 2025 pm 01:51 PM

This article explores in-depth the mechanism of sending multiple HTTP requests on the same TCP Socket, namely, HTTP persistent connection (Keep-Alive). The article clarifies the difference between HTTP/1.x and HTTP/2 protocols, emphasizes the importance of server-side support for persistent connections, and how to correctly handle Connection: close response headers. By analyzing common errors and providing best practices, we aim to help developers build efficient and robust HTTP clients.

How to implement an interface in Java? How to implement an interface in Java? Sep 18, 2025 am 05:31 AM

Use the implements keyword to implement the interface. The class needs to provide specific implementations of all methods in the interface. It supports multiple interfaces and is separated by commas to ensure that the methods are public. The default and static methods after Java 8 do not need to be rewrite.

Understanding Java Generics and Wildcards Understanding Java Generics and Wildcards Sep 20, 2025 am 01:58 AM

Javagenericsprovidecompile-timetypesafetyandeliminatecastingbyallowingtypeparametersonclasses,interfaces,andmethods;wildcards(?,?extendsType,?superType)handleunknowntypeswithflexibility.1.UseunboundedwildcardwhentypeisirrelevantandonlyreadingasObject

Java Tutorial: How to Flatten a Nested ArrayList and Fill its Elements into an Array Java Tutorial: How to Flatten a Nested ArrayList and Fill its Elements into an Array Sep 18, 2025 am 07:24 AM

This tutorial details how to efficiently process nested ArrayLists containing other ArrayLists in Java and merge all its internal elements into a single array. The article will provide two core solutions through the flatMap operation of the Java 8 Stream API: first flattening into a list and then filling the array, and directly creating a new array to meet the needs of different scenarios.

How to read a properties file in Java? How to read a properties file in Java? Sep 16, 2025 am 05:01 AM

Use the Properties class to read Java configuration files easily. 1. Put config.properties into the resource directory, load it through getClassLoader().getResourceAsStream() and call the load() method to read the database configuration. 2. If the file is in an external path, use FileInputStream to load it. 3. Use getProperty(key,defaultValue) to handle missing keys and provide default values ​​to ensure exception handling and input verification.

See all articles