本文使用jinfo命令工具~
jinfo用于查看运行中的java程序的参数,同时也支持在运行时修改部分参数~ 参数包括Java System属性和JVM命令行参数。
在使用jinfo命令之前,可以先使用jps -help来查看jps命令相关的使用方法,包括有哪些参数等~
[root@dev18 ~]# jinfo -helpUsage: jinfo [option](to connect to running process) jinfo [option] (to connect to a core file) jinfo [option] [server_id@] (to connect to remote debug server)where
jinfo 需要pid,所以需要和jps配合使用,也就是先使用jps获取pid信息,然后使用jinfo来处理~
[root@dev18 ~]# jps -l1656 org.elasticsearch.bootstrap.Elasticsearch18011 sun.tools.jps.Jps12905 org.apache.zookeeper.server.quorum.QuorumPeerMain4308 /srv/activemq/apache-activemq-5.14.3//bin/activemq.jar[root@dev18 ~]#
接下来,本文使用Zookeeper的服务为例,其pid为12905
使用jinfo -flags 12905打印JVM flags信息
[root@dev18 ~]# jinfo -flags 12905Attaching to process ID 12905, please wait...Debugger attached successfully.Server compiler detected.JVM version is 24.71-b01-Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false[root@dev18 ~]#
使用jinfo -sysprops 12905打印Java系统属性信息
[root@dev18 ~]# jinfo -sysprops 12905Attaching to process ID 12905, please wait...Debugger attached successfully.Server compiler detected.JVM version is 24.71-b01java.runtime.name = Java(TM) SE Runtime Environmentjava.vm.version = 24.71-b01sun.boot.library.path = /usr/java/jdk1.7.0_71/jre/lib/amd64zookeeper.root.logger = INFO,CONSOLEjava.vendor.url = http://java.oracle.com/java.vm.vendor = Oracle Corporationcom.sun.management.jmxremote.local.only = falsepath.separator = :java.rmi.server.randomIDs = truefile.encoding.pkg = sun.iojava.vm.name = Java HotSpot(TM) 64-Bit Server VMsun.os.patch.level = unknownsun.java.launcher = SUN_STANDARDuser.country = USuser.dir = /srv/zookeepers/zookeeper/binjava.vm.specification.name = Java Virtual Machine Specificationjava.runtime.version = 1.7.0_71-b14java.awt.graphicsenv = sun.awt.X11GraphicsEnvironmentos.arch = amd64java.endorsed.dirs = /usr/java/jdk1.7.0_71/jre/lib/endorsedzookeeper.log.dir = .java.io.tmpdir = /tmpline.separator = java.vm.specification.vendor = Oracle Corporationos.name = Linuxsun.jnu.encoding = UTF-8java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/libjava.specification.name = Java Platform API Specificationjava.class.version = 51.0sun.management.compiler = HotSpot 64-Bit Tiered Compilersos.version = 2.6.32-573.el6.x86_64user.home = /rootuser.timezone = Asia/Chungkingjava.awt.printerjob = sun.print.PSPrinterJobfile.encoding = UTF-8java.specification.version = 1.7user.name = rootjava.class.path = /srv/zookeepers/zookeeper/bin/../build/classes:/srv/zookeepers/zookeeper/bin/../build/lib/*.jar:/srv/zookeepers/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/srv/zookeepers/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/srv/zookeepers/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/srv/zookeepers/zookeeper/bin/../lib/log4j-1.2.16.jar:/srv/zookeepers/zookeeper/bin/../lib/jline-0.9.94.jar:/srv/zookeepers/zookeeper/bin/../zookeeper-3.4.9.jar:/srv/zookeepers/zookeeper/bin/../src/java/lib/*.jar:/srv/zookeepers/zookeeper/bin/../conf:.:/usr/java/jdk1.7.0_71/jre/lib/rt.jar:/usr/java/jdk1.7.0_71/lib/dt.jar:/usr/java/jdk1.7.0_71/lib/tools.jarcom.sun.management.jmxremote = java.vm.specification.version = 1.7sun.arch.data.model = 64sun.java.command = org.apache.zookeeper.server.quorum.QuorumPeerMain /srv/zookeepers/zookeeper/bin/../conf/zoo.cfgjava.home = /usr/java/jdk1.7.0_71/jreuser.language = enjava.specification.vendor = Oracle Corporationawt.toolkit = sun.awt.X11.XToolkitjava.vm.info = mixed modejava.version = 1.7.0_71java.ext.dirs = /usr/java/jdk1.7.0_71/jre/lib/ext:/usr/java/packages/lib/extsun.boot.class.path = /usr/java/jdk1.7.0_71/jre/lib/resources.jar:/usr/java/jdk1.7.0_71/jre/lib/rt.jar:/usr/java/jdk1.7.0_71/jre/lib/sunrsasign.jar:/usr/java/jdk1.7.0_71/jre/lib/jsse.jar:/usr/java/jdk1.7.0_71/jre/lib/jce.jar:/usr/java/jdk1.7.0_71/jre/lib/charsets.jar:/usr/java/jdk1.7.0_71/jre/lib/jfr.jar:/usr/java/jdk1.7.0_71/jre/classesjava.vendor = Oracle Corporationfile.separator = /java.vendor.url.bug = http://bugreport.sun.com/bugreport/sun.io.unicode.encoding = UnicodeLittlesun.cpu.endian = littlesun.cpu.isalist = [root@dev18 ~]#
不指定option,同时打印JVM flags和Java系统属性~
如 jinfo 12905
[root@dev18 ~]# jinfo 12905Attaching to process ID 12905, please wait...Debugger attached successfully.Server compiler detected.JVM version is 24.71-b01Java System Properties:java.runtime.name = Java(TM) SE Runtime Environmentjava.vm.version = 24.71-b01sun.boot.library.path = /usr/java/jdk1.7.0_71/jre/lib/amd64zookeeper.root.logger = INFO,CONSOLEjava.vendor.url = http://java.oracle.com/java.vm.vendor = Oracle Corporationcom.sun.management.jmxremote.local.only = falsepath.separator = :java.rmi.server.randomIDs = truefile.encoding.pkg = sun.iojava.vm.name = Java HotSpot(TM) 64-Bit Server VMsun.os.patch.level = unknownsun.java.launcher = SUN_STANDARDuser.country = USuser.dir = /srv/zookeepers/zookeeper/binjava.vm.specification.name = Java Virtual Machine Specificationjava.runtime.version = 1.7.0_71-b14java.awt.graphicsenv = sun.awt.X11GraphicsEnvironmentos.arch = amd64java.endorsed.dirs = /usr/java/jdk1.7.0_71/jre/lib/endorsedzookeeper.log.dir = .java.io.tmpdir = /tmpline.separator = java.vm.specification.vendor = Oracle Corporationos.name = Linuxsun.jnu.encoding = UTF-8java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/libjava.specification.name = Java Platform API Specificationjava.class.version = 51.0sun.management.compiler = HotSpot 64-Bit Tiered Compilersos.version = 2.6.32-573.el6.x86_64user.home = /rootuser.timezone = Asia/Chungkingjava.awt.printerjob = sun.print.PSPrinterJobfile.encoding = UTF-8java.specification.version = 1.7user.name = rootjava.class.path = /srv/zookeepers/zookeeper/bin/../build/classes:/srv/zookeepers/zookeeper/bin/../build/lib/*.jar:/srv/zookeepers/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/srv/zookeepers/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/srv/zookeepers/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/srv/zookeepers/zookeeper/bin/../lib/log4j-1.2.16.jar:/srv/zookeepers/zookeeper/bin/../lib/jline-0.9.94.jar:/srv/zookeepers/zookeeper/bin/../zookeeper-3.4.9.jar:/srv/zookeepers/zookeeper/bin/../src/java/lib/*.jar:/srv/zookeepers/zookeeper/bin/../conf:.:/usr/java/jdk1.7.0_71/jre/lib/rt.jar:/usr/java/jdk1.7.0_71/lib/dt.jar:/usr/java/jdk1.7.0_71/lib/tools.jarcom.sun.management.jmxremote = java.vm.specification.version = 1.7sun.arch.data.model = 64sun.java.command = org.apache.zookeeper.server.quorum.QuorumPeerMain /srv/zookeepers/zookeeper/bin/../conf/zoo.cfgjava.home = /usr/java/jdk1.7.0_71/jreuser.language = enjava.specification.vendor = Oracle Corporationawt.toolkit = sun.awt.X11.XToolkitjava.vm.info = mixed modejava.version = 1.7.0_71java.ext.dirs = /usr/java/jdk1.7.0_71/jre/lib/ext:/usr/java/packages/lib/extsun.boot.class.path = /usr/java/jdk1.7.0_71/jre/lib/resources.jar:/usr/java/jdk1.7.0_71/jre/lib/rt.jar:/usr/java/jdk1.7.0_71/jre/lib/sunrsasign.jar:/usr/java/jdk1.7.0_71/jre/lib/jsse.jar:/usr/java/jdk1.7.0_71/jre/lib/jce.jar:/usr/java/jdk1.7.0_71/jre/lib/charsets.jar:/usr/java/jdk1.7.0_71/jre/lib/jfr.jar:/usr/java/jdk1.7.0_71/jre/classesjava.vendor = Oracle Corporationfile.separator = /java.vendor.url.bug = http://bugreport.sun.com/bugreport/sun.io.unicode.encoding = UnicodeLittlesun.cpu.endian = littlesun.cpu.isalist = VM Flags:-Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false[root@dev18 ~]#
查看某个参数的值,jinfo -flag SurvivorRatio 12905
[root@dev18 ~]# jinfo -flag SurvivorRatio 12905-XX:SurvivorRatio=8[root@dev18 ~]#
我们通过-XX:+PrintFlagsFinal -version参数可以获取JVM的所有选项,因为这样的信息很多,我们只列出可管理 (manageable) 的参数信息,如:
[root@dev18 ~]# java -XX:+PrintFlagsFinal -version | grep manageable intx CMSAbortablePrecleanWaitMillis = 100 {manageable} intx CMSWaitDuration = 2000 {manageable} bool HeapDumpAfterFullGC = false {manageable} bool HeapDumpBeforeFullGC = false {manageable} bool HeapDumpOnOutOfMemoryError = false {manageable} ccstr HeapDumpPath = {manageable} uintx MaxHeapFreeRatio = 100 {manageable} uintx MinHeapFreeRatio = 0 {manageable} bool PrintClassHistogram = false {manageable} bool PrintClassHistogramAfterFullGC = false {manageable} bool PrintClassHistogramBeforeFullGC = false {manageable} bool PrintConcurrentLocks = false {manageable} bool PrintGC = false {manageable} bool PrintGCDateStamps = false {manageable} bool PrintGCDetails = false {manageable} bool PrintGCTimeStamps = false {manageable} java version "1.7.0_71"Java(TM) SE Runtime Environment (build 1.7.0_71-b14)Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)[root@dev18 ~]#
从上述信息中可以看到,MaxHeapFreeRatio的值为100,我们尝试去修改一下这个值,将其改成80~
修改MaxHeapFreeRatio的值,使用jinfo -flag MaxHeapFreeRatio=80 12905
然后查一下修改后MaxHeapFreeRatio的值已经为80~
[root@dev18 ~]# jinfo -flag MaxHeapFreeRatio 12905-XX:MaxHeapFreeRatio=80
重新将MaxHeapFreeRatio设置为默认的100~
[root@dev18 ~]# jinfo -flag MaxHeapFreeRatio=100 12905[root@dev18 ~]# jinfo -flag MaxHeapFreeRatio 12905-XX:MaxHeapFreeRatio=100[root@dev18 ~]#
本文使用jinfo命令工具给出相关的示例,有兴趣的读者可以动手操作一下~ :)