jinfo
jinfo全稱Java Configuration Info兔甘,所以它的主要作用是實時查看和調(diào)整JVM配置參數(shù),
查看JVM參數(shù)
用法:jinfo -flag <name> PID
例如:
jinfo -flag MaxMetaspaceSize 18348,得到結(jié)果-XX:MaxMetaspaceSize=536870912崔挖,即MaxMetaspaceSize為512M
jinfo -flag ThreadStackSize 18348卵史,得到結(jié)果-XX:ThreadStackSize=256,即Xss為256K
調(diào)整JVM參數(shù)
用法:
如果是布爾類型的JVM參數(shù): jinfo -flag [+|-]<name> PID躬审,enable or disable the named VM flag
如果是數(shù)字/字符串類型的JVM參數(shù) jinfo -flag <name>=<value> PID,to set the named VM flag to the given value
那么哪些參數(shù)可以通過jinfo實時調(diào)整呢蟆盐,請往下看承边;
查看所有支持動態(tài)修改的JVM參數(shù)
如何查看JVM支持的所有可以通過info動態(tài)修改的JVM參數(shù)參數(shù)呢?在官方文檔中有一段這樣的描述:
Flags marked as manageable are dynamically writeable through the JDK management interface (com.sun.management.HotSpotDiagnosticMXBean API) and also through JConsole.
也就是說石挂,標記為manageable的參數(shù)或者通過com.sun.management.HotSpotDiagnosticMXBean這個類的接口得到救军;
方法一 -- 標記為manageable的Flags
Linux環(huán)境:java -XX:+PrintFlagsInitial | grep manageable
Window環(huán)境:java -XX:+PrintFlagsInitial | findstr manageable
運行結(jié)果如下圖所示:
方法二 -- 通過HotSpotDiagnosticMXBean API
查看該類的 Java Doc称诗,有一個getDiagnosticOptions()這樣的方法膀懈,該方法的詳細描述如下:
Returns a list of VMOption objects for all diagnostic options. A diagnostic option is a writeable VM option that can be set dynamically mainly for troubleshooting and diagnosis.
Bingo找到了入篮,接下來通過Java代碼調(diào)用該API得到所有可動態(tài)修改的JVM參數(shù), java代碼如下:
/**
* @author afei
* @version 1.0.0
* @since 2017年07月25日
*/
public class DiagnosticOptionsTest {
public static void main(String[] args) {
HotSpotDiagnostic mxBean = new HotSpotDiagnostic();
List<VMOption> diagnosticVMOptions = mxBean.getDiagnosticOptions();
for (VMOption vmOption:diagnosticVMOptions){
System.out.println(vmOption.getName() + " = " + vmOption.getValue());
}
}
}
說明:
由于HotSpotDiagnosticMXBean 是接口(public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean ),所以需要通過它唯一的實現(xiàn)類HotSpotDiagnostic 來調(diào)用這個方法里伯;
運行結(jié)果如下:
HeapDumpBeforeFullGC = false
HeapDumpAfterFullGC = false
HeapDumpOnOutOfMemoryError = false
HeapDumpPath =
CMSAbortablePrecleanWaitMillis = 100
CMSWaitDuration = 2000
CMSTriggerInterval = -1
PrintGC = false
PrintGCDetails = false
PrintGCDateStamps = false
PrintGCTimeStamps = false
PrintGCID = false
PrintClassHistogramBeforeFullGC = false
PrintClassHistogramAfterFullGC = false
PrintClassHistogram = false
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
PrintConcurrentLocks = false
UnlockCommercialFeatures = false
這些JVM參數(shù)就是所有可以通過jinfo動態(tài)修改的參數(shù)城瞎;