1. 程式人生 > >Java常用命令列工具

Java常用命令列工具

常用的Java命令列工具的使用梳理,方便以後線上問題排查處理.

示例使用的虛擬機器版本(JVM自帶命令列工具在bin目錄下)

[[email protected] ~]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
[[email protected] ~]# which java
/usr/local/jdk1.8.0_121/bin/java
[
[email protected]
~]# ls /usr/local/jdk1.8.0_121/bin/ appletviewer jarsigner javah jcmd jhat jmc.ini jstat orbd rmiregistry unpack200 ControlPanel java javap jconsole jinfo jps jstatd pack200 schemagen wsgen extcheck javac javapackager jcontrol jjs jrunscript jvisualvm policytool serialver wsimport idlj javadoc java-rmi.cgi jdb jmap jsadebugd keytool rmic servertool xjc jar javafxpackager javaws jdeps jmc jstack native2ascii rmid tnameserv

常用Java命令列工具

  • javap : java位元組碼資訊檢視工具
  • jps : java虛擬機器程序資訊工具
  • jinfo : java虛擬機器程序配置資訊工具
  • jstat : java虛擬機器程序統計資訊監控工具
  • jstack : java虛擬機器程序堆疊跟蹤工具, 製作執行緒Dump
  • jmap : java虛擬機器程序堆記憶體對映,製作堆Dump
  • jhat : java虛擬機器堆轉儲快照分析工具
  • jconsole : 用於提供JVM活動的圖形化檢視,包括執行緒的使用、類的使用和GC活動.
  • jvisualvm: 監控JVM的GUI工具,可用來剖析執行的應用,分析JVM堆轉儲.

術語認知

Java Dump介紹

Java虛擬機器的執行時快照.將Java虛擬機器執行時的狀態和資訊儲存到檔案, 用於補足傳統Bug分析手段的不足,可在任何Java環境使用; 資訊量充足;針對非功能正確性的Bug(像多執行緒幵發、記憶體洩漏)

  • ThreadDump : 包含所有執行緒的執行狀態.純文字格式
  • HeapDump: 包含執行緒Dump,幵包含所有堆物件的狀態,二進位制格式.

製作Java Dump

使用Java虛擬機器配置

配置jvm引數 -XX:+HeapDumpOnOutOfMemoryError 讓虛擬機器在OOM異常出現之後自動生成dump檔案.
配置jvm引數 -XX:+HeapDumpOnCtrlBreak 使用Ctrl+Break鍵,讓虛擬機器生成dump檔案.

使用圖形化工具

使用JDK自帶工具: Java VisualVM

Linux系統下通過kill命令

Linux系統下通過kill -3 命令傳送程序退出訊號'嚇唬'一下虛擬機器,也能拿到dump檔案.

使用Java命令列工具
  • jstack:列印執行緒的棧資訊,製作執行緒Dump.
  • jmap:列印記憶體對映,製作堆Dump.

命令列工具-jps

jps(Jvm Process Status Tool) 虛擬機器程序狀態工具, 可以用於檢視當前執行的java行程以及相關引數

jps語法

[[email protected] ~]# jps -help
usage: jps [-help]
       jps [-q] [-mlvV] [<hostid>]

Definitions:
    <hostid>:      <hostname>[:<port>]

引數說明

  • -q : 忽略輸出的類名、Jar名以及傳遞給main方法的引數,只輸出pid
  • -m : 輸出虛擬機器程序啟動時傳遞給主類main()方法的引數
  • -l : 輸出主類完整的包名和類名,如果程序執行的是jar包,輸出jar包路徑
  • -v : 輸出虛擬機器程序啟動時jvm引數
  • -V : 輸出通過標記的檔案傳遞給JVM的引數(.hotspotrc檔案,或者是通過引數-XX:Flags=指定的檔案)

jps示例

輸出Java程序pid
[[email protected] ~]# jps -q
3126
6940
輸出主類包名和類名
[[email protected] ~]# jps -l
3126 org.apache.catalina.startup.Bootstrap
6955 sun.tools.jps.Jps
輸出程序啟動時傳遞給主類的方法引數
[[email protected] ~]# jps -m
3126 Bootstrap start
6970 Jps -m
[[email protected] ~]# jps -lm
3126 org.apache.catalina.startup.Bootstrap start
6985 sun.tools.jps.Jps -lm
輸出通過標記檔案傳遞給Jvm的引數
[[email protected] ~]# jps -V
7011 Jps
3126 Bootstrap
[[email protected] ~]# jps -lV
7026 sun.tools.jps.Jps
3126 org.apache.catalina.startup.Bootstrap
輸出程序啟動時的jvm引數
[[email protected] ~]# jps -v
7073 Jps -Dapplication.home=/usr/local/jdk1.8.0_121 -Xms8m
3126 Bootstrap -Djava.util.logging.config.file=/usr/local/confluence-6.0.3/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Xms1536m -Xmx2048m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/usr/local/confluence-6.0.3/logs/gc-2017-10-15_16-08-58.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Dhttp.socket.timeout=10 -Djava.endorsed.dirs=/usr/local/confluence-6.0.3/endorsed -Dcatalina.base=/usr/local/confluence-6.0.3 -Dcatalina.home=/usr/local/confluence-6.0.3 -Djava.io.tmpdir=/usr/local/confluence-6.0.3/temp
[[email protected] ~]# jps -lv
7088 sun.tools.jps.Jps -Dapplication.home=/usr/local/jdk1.8.0_121 -Xms8m
3126 org.apache.catalina.startup.Bootstrap -Djava.util.logging.config.file=/usr/local/confluence-6.0.3/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Xms1536m -Xmx2048m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/usr/local/confluence-6.0.3/logs/gc-2017-10-15_16-08-58.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Dhttp.socket.timeout=10 -Djava.endorsed.dirs=/usr/local/confluence-6.0.3/endorsed -Dcatalina.base=/usr/local/confluence-6.0.3 -Dcatalina.home=/usr/local/confluence-6.0.3 -Djava.io.tmpdir=/usr/local/confluence-6.0.3/temp
[[email protected] ~]# jps -lmv
3126 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/usr/local/confluence-6.0.3/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Xms1536m -Xmx2048m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/usr/local/confluence-6.0.3/logs/gc-2017-10-15_16-08-58.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Dhttp.socket.timeout=10 -Djava.endorsed.dirs=/usr/local/confluence-6.0.3/endorsed -Dcatalina.base=/usr/local/confluence-6.0.3 -Dcatalina.home=/usr/local/confluence-6.0.3 -Djava.io.tmpdir=/usr/local/confluence-6.0.3/temp
7103 sun.tools.jps.Jps -lmv -Dapplication.home=/usr/local/jdk1.8.0_121 -Xms8m

命令列工具-jinfo

jinfo(Configuration Info for Java) 作用是實時地檢視和調整虛擬機器各項引數.

jinfo語法

[[email protected] ~]# jinfo -help
Usage:
    jinfo [option] <pid>
        (to connect to running process)
    jinfo [option] <executable <core>
        (to connect to a core file)
    jinfo [option] [[email protected]]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    -flag <name>         to print the value of the named VM flag
    -flag [+|-]<name>    to enable or disable the named VM flag
    -flag <name>=<value> to set the named VM flag to the given value
    -flags               to print VM flags
    -sysprops            to print Java system properties
    <no option>          to print both of the above
    -h | -help           to print this help message

jinfo示例

獲取應用程序所有配置資訊
[[email protected] ~]# jps -l
3126 org.apache.catalina.startup.Bootstrap
4076 sun.tools.jps.Jps
[[email protected] ~]# jinfo 3126
Attaching to process ID 3126, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
Java System Properties:

java.vendor = Oracle Corporation
sun.java.launcher = SUN_STANDARD
catalina.base = /usr/local/confluence-6.0.3
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
catalina.useNaming = true
os.name = Linux
java.util.logging.config.file = /usr/local/confluence-6.0.3/conf/logging.properties
sun.boot.class.path = /usr/local/jdk1.8.0_121/jre/lib/resources.jar:/usr/local/jdk1.8.0_121/jre/lib/rt.jar:/usr/local/jdk1.8.0_121/jre/lib/sunrsasign.jar:/usr/local/jdk1.8.0_121/jre/lib/jsse.jar:/usr/local/jdk1.8.0_121/jre/lib/jce.jar:/usr/local/jdk1.8.0_121/jre/lib/charsets.jar:/usr/local/jdk1.8.0_121/jre/lib/jfr.jar:/usr/local/jdk1.8.0_121/jre/classes
java.vm.specification.vendor = Oracle Corporation
java.runtime.version = 1.8.0_121-b13
atlassian.plugins.enable.wait = 300
user.name = root
shared.loader = 
tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar
com.sun.jndi.ldap.connect.pool.protocol = plain ssl
com.sun.jndi.ldap.connect.pool.authentication = simple
tomcat.util.buf.StringCache.byte.enabled = true
user.language = zh
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
sun.boot.library.path = /usr/local/jdk1.8.0_121/jre/lib/amd64
atlassian.enable.spring.strong.cache.bean.metadata = true
jdk.tls.ephemeralDHKeySize = 2048
java.version = 1.8.0_121
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
user.timezone = Asia/Shanghai
sun.arch.data.model = 64
atlassian.enable.spring.strong.cache.bean.metadata.flush = true
java.endorsed.dirs = /usr/local/confluence-6.0.3/endorsed
sun.cpu.isalist = 
sun.jnu.encoding = UTF-8
file.encoding.pkg = sun.io
org.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE = 32768
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.
file.separator = /
java.specification.name = Java Platform API Specification
java.class.version = 52.0
user.country = CN
java.home = /usr/local/jdk1.8.0_121/jre
atlassian.org.osgi.framework.bootdelegation.extra = org.apache.lucene.*
java.vm.info = mixed mode
os.version = 3.10.0-514.6.1.el7.x86_64
com.sun.jndi.ldap.connect.pool.prefsize = 10
sun.font.fontmanager = sun.awt.X11FontManager
path.separator = :
java.vm.version = 25.121-b13
java.protocol.handler.pkgs = org.apache.catalina.webresources
java.awt.printerjob = sun.print.PSPrinterJob
sun.io.unicode.encoding = UnicodeLittle
sun.java2d.opengl = true
awt.toolkit = sun.awt.X11.XToolkit
package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
java.naming.factory.url.pkgs = org.apache.naming
user.home = /root
java.specification.vendor = Oracle Corporation
tomcat.util.scan.StandardJarScanFilter.jarsToSkip = bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-*.jar,tomcat-api.jar,tomcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni.jar,tomcat-websocket.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,jstl.jar,taglibs-standard-spec-*.jar,geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-*.jar,ant-launcher.jar,cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,xom-*.jar
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
java.runtime.name = Java(TM) SE Runtime Environment
sun.java.command = org.apache.catalina.startup.Bootstrap start
java.class.path = /usr/local/confluence-6.0.3/bin/bootstrap.jar:/usr/local/confluence-6.0.3/bin/tomcat-juli.jar
hibernate.bytecode.use_reflection_optimizer = true
com.sun.jndi.ldap.connect.pool.maxsize = 0
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.version = 1.8
catalina.home = /usr/local/confluence-6.0.3
sun.cpu.endian = little
sun.os.patch.level = unknown
java.awt.headless = true
java.io.tmpdir = /usr/local/confluence-6.0.3/temp
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
server.loader = 
os.arch = amd64
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
java.ext.dirs = /usr/local/jdk1.8.0_121/jre/lib/ext:/usr/java/packages/lib/ext
user.dir = /
com.sun.jndi.ldap.connect.pool.initsize = 1
line.separator = 

java.vm.name = Java HotSpot(TM) 64-Bit Server VM
file.encoding = UTF-8
com.sun.jndi.ldap.connect.pool.timeout = 30000
http.socket.timeout = 10
java.specification.version = 1.8
plugin.webresource.javascript.try.catch.wrapping = true

VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:ConcGCThreads=1 -XX:G1HeapRegionSize=1048576 -XX:G1ReservePercent=20 -XX:GCLogFileSize=2097152 -XX:InitialHeapSize=1610612736 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=2147483648 -XX:MaxNewSize=1287651328 -XX:MinHeapDeltaBytes=1048576 -XX:NumberOfGCLogFiles=5 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:-PrintGCDetails -XX:+PrintGCTimeStamps -XX:-PrintTenuringDistribution -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC -XX:+UseGCLogFileRotation 
Command line:  -Djava.util.logging.config.file=/usr/local/confluence-6.0.3/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Xms1536m -Xmx2048m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/usr/local/confluence-6.0.3/logs/gc-2017-10-15_16-08-58.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Dhttp.socket.timeout=10 -Djava.endorsed.dirs=/usr/local/confluence-6.0.3/endorsed -Dcatalina.base=/usr/local/confluence-6.0.3 -Dcatalina.home=/usr/local/confluence-6.0.3 -Djava.io.tmpdir=/usr/local/confluence-6.0.3/temp
獲取應用程序的命令列引數資訊
[[email protected] ~]# jinfo -flags 3126
Attaching to process ID 3126, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
Non-default VM flags: -XX:CICompilerCount=3 -XX:ConcGCThreads=1 -XX:G1HeapRegionSize=1048576 -XX:G1ReservePercent=20 -XX:GCLogFileSize=2097152 -XX:InitialHeapSize=1610612736 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=2147483648 -XX:MaxNewSize=1287651328 -XX:MinHeapDeltaBytes=1048576 -XX:NumberOfGCLogFiles=5 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:-PrintGCDetails -XX:+PrintGCTimeStamps -XX:-PrintTenuringDistribution -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC -XX:+UseGCLogFileRotation 
Command line:  -Djava.util.logging.config.file=/usr/local/confluence-6.0.3/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Xms1536m -Xmx2048m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/usr/local/confluence-6.0.3/logs/gc-2017-10-15_16-08-58.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Dhttp.socket.timeout=10 -Djava.endorsed.dirs=/usr/local/confluence-6.0.3/endorsed -Dcatalina.base=/usr/local/confluence-6.0.3 -Dcatalina.home=/usr/local/confluence-6.0.3 -Djava.io.tmpdir=/usr/local/confluence-6.0.3/temp
[[email protected] ~]#
[[email protected] ~]# jinfo -flag PrintGCDetails 3126
-XX:-PrintGCDetails
[[email protected] ~]# jinfo -flag MaxHeapSize 3126
-XX:MaxHeapSize=2147483648
列印應用程序的系統引數資訊(System.getProperties())
[[email protected] ~]# jinfo -sysprops 3126
Attaching to process ID 3126, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
java.vendor = Oracle Corporation
sun.java.launcher = SUN_STANDARD
catalina.base = /usr/local/confluence-6.0.3
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
catalina.useNaming = true
os.name = Linux
java.util.logging.config.file = /usr/local/confluence-6.0.3/conf/logging.properties
sun.boot.class.path = /usr/local/jdk1.8.0_121/jre/lib/resources.jar:/usr/local/jdk1.8.0_121/jre/lib/rt.jar:/usr/local/jdk1.8.0_121/jre/lib/sunrsasign.jar:/usr/local/jdk1.8.0_121/jre/lib/jsse.jar:/usr/local/jdk1.8.0_121/jre/lib/jce.jar:/usr/local/jdk1.8.0_121/jre/lib/charsets.jar:/usr/local/jdk1.8.0_121/jre/lib/jfr.jar:/usr/local/jdk1.8.0_121/jre/classes
java.vm.specification.vendor = Oracle Corporation
java.runtime.version = 1.8.0_121-b13
atlassian.plugins.enable.wait = 300
user.name = root
shared.loader = 
tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar
com.sun.jndi.ldap.connect.pool.protocol = plain ssl
com.sun.jndi.ldap.connect.pool.authentication = simple
tomcat.util.buf.StringCache.byte.enabled = true
user.language = zh
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
sun.boot.library.path = /usr/local/jdk1.8.0_121/jre/lib/amd64
atlassian.enable.spring.strong.cache.bean.metadata = true
jdk.tls.ephemeralDHKeySize = 2048
java.version = 1.8.0_121
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
user.timezone = Asia/Shanghai
sun.arch.data.model = 64
atlassian.enable.spring.strong.cache.bean.metadata.flush = true
java.endorsed.dirs = /usr/local/confluence-6.0.3/endorsed
sun.cpu.isalist = 
sun.jnu.encoding = UTF-8
file.encoding.pkg = sun.io
org.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE = 32768
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.
file.separator = /
java.specification.name = Java Platform API Specification
java.class.version = 52.0
user.country = CN
java.home = /usr/local/jdk1.8.0_121/jre
atlassian.org.osgi.framework.bootdelegation.extra = org.apache.lucene.*
java.vm.info = mixed mode
os.version = 3.10.0-514.6.1.el7.x86_64
com.sun.jndi.ldap.connect.pool.prefsize = 10
sun.font.fontmanager = sun.awt.X11FontManager
path.separator = :
java.vm.version = 25.121-b13
java.protocol.handler.pkgs = org.apache.catalina.webresources
java.awt.printerjob = sun.print.PSPrinterJob
sun.io.unicode.encoding = UnicodeLittle
sun.java2d.opengl = true
awt.toolkit = sun.awt.X11.XToolkit
package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
java.naming.factory.url.pkgs = org.apache.naming
user.home = /root
java.specification.vendor = Oracle Corporation
tomcat.util.scan.StandardJarScanFilter.jarsToSkip = bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-*.jar,tomcat-api.jar,tomcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni.jar,tomcat-websocket.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,jstl.jar,taglibs-standard-spec-*.jar,geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-*.jar,ant-launcher.jar,cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,xom-*.jar
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
java.runtime.name = Java(TM) SE Runtime Environment
sun.java.command = org.apache.catalina.startup.Bootstrap start
java.class.path = /usr/local/confluence-6.0.3/bin/bootstrap.jar:/usr/local/confluence-6.0.3/bin/tomcat-juli.jar
hibernate.bytecode.use_reflection_optimizer = true
com.sun.jndi.ldap.connect.pool.maxsize = 0
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.version = 1.8
catalina.home = /usr/local/confluence-6.0.3
sun.cpu.endian = little
sun.os.patch.level = unknown
java.awt.headless = true
java.io.tmpdir = /usr/local/confluence-6.0.3/temp
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
server.loader = 
os.arch = amd64
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
java.ext.dirs = /usr/local/jdk1.8.0_121/jre/lib/ext:/usr/java/packages/lib/ext
user.dir = /
com.sun.jndi.ldap.connect.pool.initsize = 1
line.separator = 

java.vm.name = Java HotSpot(TM) 64-Bit Server VM
file.encoding = UTF-8
com.sun.jndi.ldap.connect.pool.timeout = 30000
http.socket.timeout = 10
java.specification.version = 1.8
plugin.webresource.javascript.try.catch.wrapping = true

命令列工具-javap

javap是jdk自帶的一個工具,可以對程式碼反編譯,也可以檢視java編譯器生成的位元組碼.

javap語法

[[email protected] ~]# javap -help
用法: javap <options> <classes>
其中, 可能的選項包括:
  -help  --help  -?        輸出此用法訊息
  -version                 版本資訊
  -v  -verbose             輸出附加資訊
  -l                       輸出行號和本地變量表
  -public                  僅顯示公共類和成員
  -protected               顯示受保護的/公共類和成員
  -package                 顯示程式包/受保護的/公共類
                           和成員 (預設)
  -p  -private             顯示所有類和成員
  -c                       對程式碼進行反彙編
  -s                       輸出內部型別簽名
  -sysinfo                 顯示正在處理的類的
                           系統資訊 (路徑, 大小, 日期, MD5 雜湊)
  -constants               顯示最終常量
  -classpath <path>        指定查詢使用者類檔案的位置
  -cp <path>               指定查詢使用者類檔案的位置
  -bootclasspath <path>    覆蓋引導類檔案的位置

javap示例

javap命令分解一個class檔案,它根據options來決定到底輸出什麼.如果沒有使用options,那麼javap將會輸出包,類裡的protected和public域以及類裡的所有方法.javap將會把它們輸出在標準輸出上

示例程式碼
[root@localhost ~]# cat ThreadDumpTest.java 
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadDumpTest {

    public static void main(String[] args) {

        ExecutorService executor = Executors.newFixedThreadPool(3);
        for(int i=0; i<5; i++){
            executor.submit(new ThreadPrint("測試執行緒"+ i));
        }
    }

    static class ThreadPrint implements Runnable{

        private String name;

        private ThreadPrint(String name){
            this.name = name;
        }

        @Override
        public void run() {
            Thread thread = Thread.currentThread();
            thread.setName(name);
            int i=0;
            while (true){
                System.out.println(thread.getName() + "輸出" + i++);
            }
        }
    }

}

[root@localhost ~]# javac ThreadDumpTest.java 
javap
[[email protected] ~]# javap ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
-version
[[email protected] ~]# javap -version ThreadDumpTest.class 
1.8.0_121
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
-sysinfo
[[email protected] ~]# javap -sysinfo ThreadDumpTest.class 
Classfile /root/ThreadDumpTest.class
  Last modified 2017-10-15; size 967 bytes
  MD5 checksum b8dce8aa07d62201b068e47eef31fa75
  Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
-constants
[[email protected] ~]# javap -constants ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
-l
[[email protected] ~]# javap -l ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
    LineNumberTable:
      line 4: 0

  public static void main(java.lang.String[]);
    LineNumberTable:
      line 8: 0
      line 9: 5
      line 10: 12
      line 9: 46
      line 12: 52
}
-c
[[email protected] ~]# javap -c ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: iconst_3
       1: invokestatic  #2                  // Method java/util/concurrent/Executors.newFixedThreadPool:(I)Ljava/util/concurrent/ExecutorService;
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iload_2
       8: iconst_5
       9: if_icmpge     52
      12: aload_1
      13: new           #3                  // class ThreadDumpTest$ThreadPrint
      16: dup
      17: new           #4                  // class java/lang/StringBuilder
      20: dup
      21: invokespecial #5                  // Method java/lang/StringBuilder."<init>":()V
      24: ldc           #6                  // String 測試執行緒
      26: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      29: iload_2
      30: invokevirtual #8                  // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: invokevirtual #9                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      36: aconst_null
      37: invokespecial #10                 // Method ThreadDumpTest$ThreadPrint."<init>":(Ljava/lang/String;LThreadDumpTest$1;)V
      40: invokeinterface #11,  2           // InterfaceMethod java/util/concurrent/ExecutorService.submit:(Ljava/lang/Runnable;)Ljava/util/concurrent/Future;
      45: pop
      46: iinc          2, 1
      49: goto          7
      52: return
}
-s
[[email protected] ~]# javap -s ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
    descriptor: ()V

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
}
-package & -public & -protected & -private
[[email protected] ~]# javap -package ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
[[email protected] ~]# javap -public ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
[[email protected] ~]# javap -protected ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
[[email protected] ~]# javap -private ThreadDumpTest.class 
Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest {
  public ThreadDumpTest();
  public static void main(java.lang.String[]);
}
-v
[[email protected] ~]# javap -v ThreadDumpTest.class 
Classfile /root/ThreadDumpTest.class
  Last modified 2017-10-15; size 967 bytes
  MD5 checksum b8dce8aa07d62201b068e47eef31fa75
  Compiled from "ThreadDumpTest.java"
public class ThreadDumpTest
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #13.#27        // java/lang/Object."<init>":()V
   #2 = Methodref          #28.#29        // java/util/concurrent/Executors.newFixedThreadPool:(I)Ljava/util/concurrent/ExecutorService;
   #3 = Class              #30            // ThreadDumpTest$ThreadPrint
   #4 = Class              #31            // java/lang/StringBuilder
   #5 = Methodref          #4.#27         // java/lang/StringBuilder."<init>":()V
   #6 = String             #32            // 測試執行緒
   #7 = Methodref          #4.#33         // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   #8 = Methodref          #4.#34         // java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
   #9 = Methodref          #4.#35         // java/lang/StringBuilder.toString:()Ljava/lang/String;
  #10 = Methodref          #3.#36         // ThreadDumpTest$ThreadPrint."<init>":(Ljava/lang/String;LThreadDumpTest$1;)V
  #11 = InterfaceMethodref #37.#38        // java/util/concurrent/ExecutorService.submit:(Ljava/lang/Runnable;)Ljava/util/concurrent/Future;
  #12 = Class              #39            // ThreadDumpTest
  #13 = Class              #40            // java/lang/Object
  #14 = Class              #41            // ThreadDumpTest$1
  #15 = Utf8               InnerClasses
  #16 = Utf8               ThreadPrint
  #17 = Utf8               <init>
  #18 = Utf8               ()V
  #19 = Utf8               Code
  #20 = Utf8               LineNumberTable
  #21 = Utf8               main
  #22 = Utf8               ([Ljava/lang/String;)V
  #23 = Utf8               StackMapTable
  #24 = Class              #42            // java/util/concurrent/ExecutorService
  #25 = Utf8               SourceFile
  #26 = Utf8               ThreadDumpTest.java
  #27 = NameAndType        #17:#18        // "<init>":()V
  #28 = Class              #43            // java/util/concurrent/Executors
  #29 = NameAndType        #44:#45        // newFixedThreadPool:(I)Ljava/util/concurrent/ExecutorService;
  #30 = Utf8               ThreadDumpTest$ThreadPrint
  #31 = Utf8               java/lang/StringBuilder
  #32 = Utf8               測試執行緒
  #33 = NameAndType        #46:#47        // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
  #34 = NameAndType        #46:#48        // append:(I)Ljava/lang/StringBuilder;
  #35 = NameAndType        #49:#50        // toString:()Ljava/lang/String;
  #36 = NameAndType        #17:#51        // "<init>":(Ljava/lang/String;LThreadDumpTest$1;)V
  #37 = Class              #42            // java/util/concurrent/ExecutorService
  #38 = NameAndType        #52:#53        // submit:(Ljava/lang/Runnable;)Ljava/util/concurrent/Future;
  #39 = Utf8               ThreadDumpTest
  #40 = Utf8               java/lang/Object
  #41 = Utf8               ThreadDumpTest$1
  #42 = Utf8               java/util/concurrent/ExecutorService
  #43 = Utf8               java/util/concurrent/Executors
  #44 = Utf8               newFixedThreadPool
  #45 = Utf8               (I)Ljava/util/concurrent/ExecutorService;
  #46 = Utf8               append
  #47 = Utf8               (Ljava/lang/String;)Ljava/lang/StringBuilder;
  #48 = Utf8               (I)Ljava/lang/StringBuilder;
  #49 = Utf8               toString
  #50 = Utf8               ()Ljava/lang/String;
  #51 = Utf8               (Ljava/lang/String;LThreadDumpTest$1;)V
  #52 = Utf8               submit
  #53 = Utf8               (Ljava/lang/Runnable;)Ljava/util/concurrent/Future;
{
  public ThreadDumpTest();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 4: 0

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=5, locals=3, args_size=1
         0: iconst_3
         1: invokestatic  #2                  // Method java/util/concurrent/Executors.newFixedThreadPool:(I)Ljava/util/concurrent/ExecutorService;
         4: astore_1
         5: iconst_0
         6: istore_2
         7: iload_2
         8: iconst_5
         9: if_icmpge     52
        12: aload_1
        13: new           #3                  // class ThreadDumpTest$ThreadPrint
        16: dup
        17: new           #4                  // class java/lang/StringBuilder
        20: dup
        21: invokespecial #5                  // Method java/lang/StringBuilder."<init>":()V
        24: ldc           #6                  // String 測試執行緒
        26: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        29: iload_2
        30: invokevirtual #8                  // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
        33: invokevirtual #9                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
        36: aconst_null
        37: invokespecial #10                 // Method ThreadDumpTest$ThreadPrint."<init>":(Ljava/lang/String;LThreadDumpTest$1;)V
        40: invokeinterface #11,  2           // InterfaceMethod java/util/concurrent/ExecutorService.submit:(Ljava/lang/Runnable;)Ljava/util/concurrent/Future;
        45: pop
        46: iinc          2, 1
        49: goto          7
        52: return
      LineNumberTable:
        line 8: 0
        line 9: 5
        line 10: 12
        line 9: 46
        line 12: 52
      StackMapTable: number_of_entries = 2
        frame_type = 253 /* append */
          offset_delta = 7
          locals = [ class java/util/concurrent/ExecutorService, int ]
        frame_type = 250 /* chop */
          offset_delta = 44
}
SourceFile: "ThreadDumpTest.java"
InnerClasses:
     static #14; //class ThreadDumpTest$1
     static #16= #3 of #12; //ThreadPrint=class ThreadDumpTest$ThreadPrint of class ThreadDumpTest

命令列工具-jstat

jstat(JVM Statistics Monitoring Tool) 是用於監視虛擬機器各種執行狀態資訊的命令列工具.它尅顯示本地或者遠端虛擬機器程序中的類裝載、記憶體、垃圾收集、JIT編譯等執行資料.

jstat語法

[[email protected] ~]# jstat -help
Usage: jstat -help|-options
       jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Definitions:
  <option>      An option reported by the -options option
  <vmid>        Virtual Machine Identifier. A vmid takes the following form:
                     <lvmid>[@<hostname>[:<port>]]
                Where <lvmid> is the local vm identifier for the target
                Java virtual machine, typically a process id; <hostname> is
                the name of the host running the target Java virtual machine;
                and <port> is the port number for the rmiregistry on the
                target host. See the jvmstat documentation for a more complete
                description of the Virtual Machine Identifier.
  <lines>       Number of samples between header lines.
  <interval>    Sampling interval. The following forms are allowed:
                    <n>["ms"|"s"]
                Where <n> is an integer and the suffix specifies the units as 
                milliseconds("ms") or seconds("s"). The default units are "ms".
  <count>       Number of samples to take before terminating.
  -J<flag>      Pass <flag> directly to the runtime system.
[[email protected] ~]# jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation

引數說明

  • -class : 監視類裝載、解除安裝數量、總空間以及類裝載所耗費的時間.
  • -compiler : 顯示編譯器編譯過的方法、耗時等資訊.
  • -gc : 顯示Java堆狀況、包括Eden區、兩個survivor區、老年代、永久代等的容量、已用空間、GC次數以及時間等資訊.
  • -gccapacity: 顯示VM記憶體中三代(young,old,perm)物件的使用和佔用大小
  • -gcutil : gc統計資訊, 輸出主要關注已使用空間佔總弓箭的百分比
  • -gccause : 與-gcutil基本相同, 會額外輸出導致上一次GC產生的原因
  • -gcnew : 顯示新生代GC狀況
  • -gcnewcapacity : 顯示內容與-gcnew相同,輸出主要關注使用到的最大最小空間
  • -gcold : 顯示老年代GC狀況
  • -gcoldcapacity : 顯示內容與-gcold相同,輸出主要關注使用到的最大最小空間
  • -printcompilation : 當前vm執行的資訊

jstat示例說明

每2s執行一次查詢統計,執行5次gc統計輸出
[[email protected] ~]# jstat -gc 3126 2 5
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
 0.0   81920.0  0.0   81920.0 566272.0 136192.0  924672.0   558080.0  224076.0 205898.7 31368.0 26476.7     36    2.526   0      0.000    2.526
 0.0   81920.0  0.0   81920.0 566272.0 136192.0  924672.0   558080.0  224076.0 205898.7 31368.0 26476.7     36    2.526   0      0.000    2.526
 0.0   81920.0  0.0   81920.0 566272.0 136192.0  924672.0   558080.0  224076.0 205898.7 31368.0 26476.7     36    2.526   0      0.000    2.526
 0.0   81920.0  0.0   81920.0 566272.0 136192.0  924672.0   558080.0  224076.0 205898.7 31368.0 26476.7     36    2.526   0      0.000    2.526
 0.0   81920.0  0.0   81920.0 566272.0 136192.0  924672.0   558080.0  224076.0 205898.7 31368.0 26476.7     36    2.526   0      0.000    2.526
-class
[[email protected] ~]# jstat -class 3126
Loaded  Bytes  Unloaded  Bytes     Time   
 39652 72532.0       15    70.1      76.55
-compiler
[[email protected] ~]# jstat -compiler 3126
Compiled Failed Invalid   Time   FailedType FailedMethod
   28416      5       0   155.87          1 com/mysql/jdbc/AbandonedConnectionCleanupThread run
-gc
[[email protected] ~]# jstat -gc 3126
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
 0.0   87040.0  0.0   87040.0 601088.0 286720.0  884736.0   513536.0  223820.0 205799.4 31368.0 26473.9     35    2.374   0      0.000    2.374
-gccapacity
[[email protected] ~]# jstat -gccapacity 3126
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC 
     0.0 2097152.0 688128.0    0.0 87040.0 601088.0        0.0  2097152.0   884736.0   884736.0      0.0 1241088.0 223820.0      0.0 1048576.0  31368.0     35     0
-gcutil & -gccause
[[email protected] ~]# jstat -gcutil 3126
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  0.00 100.00  40.03  58.04  91.95  84.40     35    2.374     0    0.000    2.374
[[email protected] ~]# jstat -gccause 3126
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC                 
  0.00 100.00  40.03  58.04  91.95  84.40     35    2.374     0    0.000    2.374 G1 Evacuation Pause  No GC 

引數說明

  • S0: 新生代中Survivor space 0區已使用空間的百分比
  • S1: 新生代中Survivor space 1區已使用空間的百分比
  • E: 新生代已使用空間的百分比
  • O: 老年代已使用空間的百分比
  • P: 永久帶已使用空間的百分比
  • YGC: 從應用程式啟動到當前,發生Yang GC 的次數
  • YGCT: 從應用程式啟動到當前,Yang GC所用的時間【單位秒】
  • FGC: 從應用程式啟動到當前,發生Full GC的次數
  • FGCT: 從應用程式啟動到當前,Full GC所用的時間
  • GCT: 從應用程式啟動到當前,用於垃圾回收的總時間【單位秒】
-gcmetacapacity
[[email protected] ~]# jstat -gcmetacapacity 3126
   MCMN       MCMX        MC       CCSMN      CCSMX       CCSC     YGC   FGC    FGCT     GCT   
       0.0  1241088.0   223820.0        0.0  1048576.0    31368.0    35     0    0.000    2.374
-gcnew & -gcnewcapacity
[[email protected] ~]# jstat -gcnew 3126
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT  
   0.0 87040.0    0.0 87040.0 15  15 43520.0 601088.0 354304.0     35    2.374
[[email protected] ~]# jstat -gcnewcapacity 3126
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC 
       0.0  2097152.0   688128.0      0.0      0.0 2097152.0  87040.0  2097152.0   601088.0    35     0
-gcold & -gcoldcapacity
[[email protected] ~]# jstat -gcold 3126
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT   
223820.0 205799.4  31368.0  26473.9    884736.0    513536.0     35     0    0.000    2.374
[[email protected] ~]# jstat -gcoldcapacity 3126
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT   
        0.0   2097152.0    884736.0    884736.0    35     0    0.000    2.374

-printcompilation

[[email protected] ~]# jstat -printcompilation 3126
Compiled  Size  Type Method
   28485    305    1 java/util/GregorianCalendar pinDayOfMonth
[[email protected] ~]# jstat -printcompilation 3126
Compiled  Size  Type Method
   28486    362    1 java/lang/StringCoding encode

命令列工具-jstack

jstack(Stack Trace for Java) 命令用於生成虛擬機器當前時刻的執行緒快照(一般稱為threaddump或者javacore檔案), 執行緒快照就是當前虛擬機器內每一條執行緒正在執行的方法堆疊的集合,生成執行緒快照的主要目的是定位執行緒出現長時間停頓的原因,如執行緒間死鎖、死迴圈、請求外部資源導致的長時間等待等.
在實際執行中,往往一次 dump的資訊,還不足以確認問題。建議產生三次 dump資訊,如果每次 dump都指向同一個問題,我們才確定問題的典型性。

jstack語法

[[email protected] ~]# jstack  -help
Usage:
    jstack [-l] <pid>
        (to connect to running process)
    jstack -F [-m] [-l] <pid>
        (to connect to a hung process)
    jstack [-m] [-l] <executable> <core>
        (to connect to a core file)
    jstack [-m] [-l] [[email protected]]<remote server IP or hostname>
        (to connect to a remote debug server)

Options:
    -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
    -m  to print both java and native frames (mixed mode)
    -l  long listing. Prints additional information about locks
    -h or -help to print this help message

引數說明

  • _F : 當正常輸出的請求不被響應時,強制輸出執行緒堆疊
  • -l : 長列表,列印關於鎖的附加資訊
  • -m : 列印java和native方法(c/c++)的堆疊資訊

jstack示例

使用jstack檢視執行緒堆疊
[[email protected] ~]# jstack -l 3126
2017-10-15 20:16:00
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode):

"Attach Listener" #171 daemon prio=9 os_prio=0 tid=0x00007feab0561800 nid=0x10d4 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

   Locked ownable synchronizers:
    - None

"lucene-tracked-searchers-pruner-pool-19-thread-1" #170 prio=5 os_prio=0 tid=0x00007fe