Junior — Middle
What command-line arguments are available for JVM configuration when launching a Java application?
sobes.tech AI
Answer from AI
JVM can be configured at startup of a Java application using various command-line arguments that influence the behavior of the virtual machine. Main categories of arguments:
-
Memory settings:
-Xms<size>— initial heap size, e.g.,-Xms512m-Xmx<size>— maximum heap size, e.g.,-Xmx1024m-Xss<size>— stack size for each thread
-
Garbage collector settings:
-XX:+UseG1GC— enable G1 collector-XX:+UseConcMarkSweepGC— enable CMS-XX:+UseParallelGC— enable parallel collector
-
Debugging and monitoring:
-Xdebug— enable debug mode-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005— remote debugging setup-XX:+PrintGCDetails— detailed garbage collection info
-
Performance tuning:
-XX:MaxPermSize=<size>(for older JVM versions) — size of the permanent generation-XX:+UseStringDeduplication— string deduplication (for G1)
-
General:
-D<name>=<value>— set system properties-verbose:gc— detailed garbage collection output
Example of startup with memory settings and G1 enabled:
java -Xms512m -Xmx2g -XX:+UseG1GC -Dconfig.file=app.properties -jar myapp.jar