Performance
performance2JvmFlagsGuide
- Path
- pkg19performance/performance2JvmFlagsGuide.java
- Package
- pkg19performance
- Study order
- 2
- Run
- Single-file source launch
- Command
- java pkg19performance/performance2JvmFlagsGuide.java
There is no in-browser runner. This is the file from the curriculum, unchanged.
1package pkg19performance;2 3/*4 * performance2JvmFlagsGuide.java5 * ------------------------------6 * Essential JVM flags for performance tuning and diagnostics.7 *8 * DEFINITION:9 * JVM flags control heap size, GC algorithm, logging, and diagnostics.10 * Architects choose flags based on workload: latency vs throughput vs memory.11 */12public class performance2JvmFlagsGuide {13 14 public static void main(String[] args) {15 System.out.println("=== Heap ===");16 System.out.println("-Xms512m -Xmx2g initial / max heap");17 System.out.println("-XX:MaxMetaspaceSize=256m class metadata cap");18 19 System.out.println("\n=== GC selection (pick ONE collector) ===");20 System.out.println("-XX:+UseG1GC G1 (default on most JDKs, balanced)");21 System.out.println("-XX:+UseZGC ZGC (low latency, large heaps)");22 System.out.println("-XX:+UseShenandoahGC Shenandoah (low pause, concurrent)");23 System.out.println("-XX:+UseParallelGC throughput-oriented");24 25 System.out.println("\n=== GC / JVM logging (Java 9+) ===");26 System.out.println("-Xlog:gc:stdout GC events to console");27 System.out.println("-Xlog:gc*:file=gc.log detailed GC log file");28 29 System.out.println("\n=== Diagnostics ===");30 System.out.println("-XX:+HeapDumpOnOutOfMemoryError");31 System.out.println("-XX:HeapDumpPath=./dumps heap dump on OOM");32 System.out.println("-XX:StartFlightRecording=duration=60s,filename=app.jfr");33 34 System.out.println("\n=== Current runtime ===");35 Runtime rt = Runtime.getRuntime();36 System.out.println("Processors : " + rt.availableProcessors());37 System.out.println("Max heap : " + rt.maxMemory() / 1024 / 1024 + " MB");38 System.out.println("Free heap : " + rt.freeMemory() / 1024 / 1024 + " MB");39 }40}