• 10 個非常重要的 HotSpot JVM 參數

    0
    Java HTML C/C++ Go 13778 次瀏覽

    1) 跟 Java 堆大小相關的 JVM 內存參數

    下面三個 JVM 參數用來指定堆的初始大小和最大值以及堆棧大小

      -Xms        設置 Java 堆的初始化大小
     -Xmx       設置最大的 Java 堆大小
     -Xss        設置Java線程堆棧大小

    2) 關于打印垃圾收集器詳情的 JVM 參數

    -verbose:gc 記錄 GC 運行以及運行時間,一般用來查看 GC 是否是應用的瓶頸

    -XX:+PrintGCDetails 記錄 GC 運行時的詳細數據信息,包括新生成對象的占用內存大小以及耗費時間等

    -XX:-PrintGCTimeStamps  打印垃圾收集的時間戳



    3) 設置 Java 垃圾收集器行為的 JVM 參數

    -XX:+UseParallelGC      使用并行垃圾收集

    -XX:-UseConcMarkSweepGC 使用并發標志掃描收集 (Introduced in 1.4.1)

    -XX:-UseSerialGC        使用串行垃圾收集 (Introduced in 5.0.)

    需要提醒的是,但你的應用是非常關鍵的、交易非常頻繁應用時,應該謹慎使用 GC 參數,因為 GC 操作是耗時的,你需要在這之中找到平衡點。

    4) JVM 調試參數,用于遠程調試

    -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000

    關于遠程調試請閱讀 How to Setup Java remote debugging in Eclipse and 10 Java debugging tips in Eclipse 

    5) 關于性能診斷的 JVM 參數

    -Xprof

    -Xrunhprof


    6) 關于類路徑方面的 JVM 參數

    Xbootclasspath 用來指定你需要加載,但不想通過校驗的類路徑。JVM 會對所有的類在加載前進行校驗并為每個類通過一個int數值來應用。這個是保證 JVM 穩定的必要過程,但比較耗時,如果你希望跳過這個過程,就把你的類通過這個參數來指定。



    7) 用于修改 Perm Gen 大小的 JVM 參數

    下面的這三個參數主要用來解決 JVM 錯誤:java.lang.OutOfMemoryError:Perm Gen Space.

    -XX:PermSize and MaxPermSize
    -XX:NewRatio=2  Ratio of new/old generation sizes.
    -XX:MaxPermSize=64m     Size of the Permanent Generation.

    8) 用來跟蹤類加載和卸載的信息

    -XX:+TraceClassLoading-XX:+TraceClassUnloading 用來打印類被加載和卸載的過程信息,這個用來診斷應用的內存泄漏問題非常有用。

    9) JVM switches related to logging

    -XX:+TraceClassLoading and -XX:+TraceClassUnloading print information class loads and unloads. Useful for investigating if you have a class leak or if old classes (like JITed Ruby methods in JRuby) are getting collected or not. You can read more about logging in Java on my post 10 Tips while logging in Java


    -XX:+PrintCompilation prints out the name of each Java method Hotspot decides to JIT compile. The list will usually show a bunch of core Java class methods initially, and then turn to methods in your application. In JRuby, it eventually starts to show Ruby methods as well

    10) 用于調試目的的 JVM 開關參數

    -XX:HeapDumpPath=./java_pid.hprof  Path to directory or file name for heap dump.

    -XX:-PrintConcurrentLocks       Print java.util.concurrent locks in Ctrl-Break thread dump.

    -XX:-PrintCommandLineFlags   Print flags that appeared on the command line.

    英文原文:hotspot-jvm-options-java-examples.html

    相似問題

    相關經驗

    相關資訊

    相關文檔

  • sesese色