常用java 命令行命令的使用及示例

1. jps :查看系统当前运行的java进程

PS C:\WINDOWS\system32> jps -h
illegal argument: -h
usage: jps [-help]
       jps [-q] [-mlvV] []

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

jps -l : 输出主类全名或是jar包路径

root@i%sf%%535%%% docs]# jps -l
14378 org.apache.catalina.startup.Bootstrap
20287 sun.tools.jps.Jps

jps -v : 输出jvm进程启动时显式指定的各种参数,排查调优时方便查看

PS C:\WINDOWS\system32> jps -v
18368 Jps -Dapplication.home=D:\Java64\jdk1.8.0_102 -Xms8m
6936  -Xms128m -Xmx1024m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -XX:+HeapD
umpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Dide.no.platform.update=true -Djb.vmOptionsFile=C:\Users\abc\.IntelliJIdea2017.2\config\idea64.exe.vmoptions -Xbootclassp
ath/a:D:\Program Files\JetBrains\IntelliJ IDEA 2017.2.2\lib\boot.jar -Didea.jre.check=true -Didea.paths.selector=IntelliJIdea2017.2 -XX:ErrorFile=C:\Users\abc\java_error_in_id
ea_%p.log -XX:HeapDumpPath=C:\Users\chenbo.MVWCHINA\java_error_in_idea.hprof

jps -m : 输出jvm启动时传给主类的参数


2. jinfo 实时查看配置jvm的各种参数

jinfo 14378 jinfo 直接加jvm进程号,将打印jvm的各种参数

[root@986or653a92Z docs]# jinfo 14378
Attaching to process ID 14378, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.111-b14
Java System Properties:

java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.111-b14
sun.boot.library.path = /usr/java/jdk1.8.0_111/jre/lib/amd64
java.protocol.handler.pkgs = org.apache.catalina.webresources
shared.loader = 
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
java.util.logging.config.file = /home/tomcat/tomcat-ins/tomcat-8081/conf/logging.properties
tomcat.util.buf.StringCache.byte.enabled = true
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = CN
tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar
user.dir = /home/tomcat/tomcat-ins/tomcat-8081
java.vm.specification.name = Java Virtual Machine Specification
PID = 14378
java.runtime.version = 1.8.0_111-b14
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/java/jdk1.8.0_111/jre/lib/endorsed
line.separator = 

java.io.tmpdir = /home/tomcat/tomcat-ins/tomcat-8081/temp
java.vm.specification.vendor = Oracle Corporation
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
java.naming.factory.url.pkgs = org.apache.naming
os.name = Linux
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
spring.beaninfo.ignore = true
java.class.version = 52.0
java.specification.name = Java Platform API Specification
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-514.26.2.el7.x86_64
user.home = /root
user.timezone = Asia/Shanghai
catalina.useNaming = true
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
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,jaspic-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,hamcrest-*.jar,easymock-*.jar,cglib-*.jar,objenesis-*.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
catalina.home = /home/tomcat/tomcat8.5.8
user.name = root
java.class.path = /home/tomcat/tomcat8.5.8/bin/bootstrap.jar:/home/tomcat/tomcat8.5.8/bin/tomcat-juli.jar
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = org.apache.catalina.startup.Bootstrap start
java.home = /usr/java/jdk1.8.0_111/jre
user.language = zh
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.8.0_111
java.ext.dirs = /usr/java/jdk1.8.0_111/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /usr/java/jdk1.8.0_111/jre/lib/resources.jar:/usr/java/jdk1.8.0_111/jre/lib/rt.jar:/usr/java/jdk1.8.0_111/jre/lib/sunrsasign.jar:/usr/java/jdk1.8.0_111/jre/lib/jsse.jar:/usr/java/jdk1.8.0_111/jre/lib/jce.jar:/usr/java/jdk1.8.0_111/jre/lib/charsets.jar:/usr/java/jdk1.8.0_111/jre/lib/jfr.jar:/usr/java/jdk1.8.0_111/jre/classes
java.awt.headless = true
server.loader = 
java.vendor = Oracle Corporation
catalina.base = /home/tomcat/tomcat-ins/tomcat-8081
jdk.tls.ephemeralDHKeySize = 2048
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.
sun.cpu.isalist = 

VM Flags:
Non-default VM flags: -XX:CICompilerCount=2 -XX:InitialHeapSize=16777216 -XX:MaxHeapSize=262144000 -XX:MaxNewSize=87359488 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=5570560 -XX:OldSize=11206656 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops 
Command line:  -Djava.util.logging.config.file=/home/tomcat/tomcat-ins/tomcat-8081/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dcatalina.base=/home/tomcat/tomcat-ins/tomcat-8081 -Dcatalina.home=/home/tomcat/tomcat8.5.8 -Djava.io.tmpdir=/home/tomcat/tomcat-ins/tomcat-8081/temp

参数相当的多,有兴趣可以一一看看。

jinfo -flag :jps -v只能查看显式的参数,想看未被显式指定的参数,就需要使用jinfo -flag命令

PS C:\WINDOWS\system32> jinfo -flag UseConcMarkSweepGC 6936
-XX:+UseConcMarkSweepGC

前面的+号表示已启用,-号表示未启用

PS C:\WINDOWS\system32> jinfo -flag UseG1GC 6936
-XX:-UseG1GC

小结:查看jvm启动参数的方式:
  1. jps -v
  2. jinfo 进程号
  3. java -XX:+PrintFlagsFinal 这个命令也可查看

(暂时总结到这)

你可能感兴趣的:(jvm,java进阶必备)