java常用命令及实践

一、jinfo

 
jinfo可以查看java进程的扩展参数
Usage:
    jinfo [option] <pid>
        (to connect to running process)
    jinfo [option] <executable <core>
        (to connect to a core file)
    jinfo [option] [server_id@]<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

常用组合

1.jinfo -flag PrintGC 20398  --查看参数PrintGC的配置,输出【-XX:+PrintGC】
2.jinfo -flag +PrintGC 20398 --动态开启PrintGC配置
3.jinfo -flag -PrintGC 20398 --动态关闭PrintGC配置
4.jinfo -flags 20398 —查看JVM的所有参数配置

一般使用动态修改以及查询所有参数配置即可

 

jinfo -flags 20398

Attaching to process ID 20398, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.112-b15
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=1073741824 -XX:MaxHeapSize=1073741824 -XX:MaxNewSize=357564416 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=357564416 -XX:OldSize=716177408 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC
Command line:  -Xms1024m -Xmx1024m -Xloggc:gc.log -XX:+PrintGCDetails

附上查看可配置的参数查询

java -XX:+PrintFlagsFinal -version|grep manageable
 
 

二、jstat

 
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.

 

 
jstat -options
-class 类加载统计
-compiler  类编译统计       
-gc  垃圾回收统计
-gccapacity  堆内存统计 
-gccause 最后一次cg原因
-gcmetacapacity 元空间容量
-gcnew 新生代GC
-gcnewcapacity 新生代内存
-gcold 老年代GC
-gcoldcapacity 老年代内存
-gcutil 类似于gccapacity
-printcompilation  HotSpot编译方法统计

option 参数总览

Option
Displays
class
类加载的行为统计。Statistics on the behavior of the class loader.
compiler
HotSpt JIT编译器行为统计。Statistics of the behavior of the HotSpot Just-in-Time compiler.
gc
垃圾回收堆的行为统计。Statistics of the behavior of the garbage collected heap.
gccapacity
各个垃圾回收代容量(young,old,perm)和他们相应的空间统计。Statistics of the capacities of the generations and their corresponding spaces.
gccause
垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因。Summary of garbage collection statistics (same as -gcutil), with the cause of the last and
gcmetacapacity
元空间统计
gcnew
新生代行为统计。Statistics of the behavior of the new generation.
gcnewcapacity
新生代与其相应的内存空间的统计。Statistics of the sizes of the new generations and its corresponding spaces.
gcold
年老代和永生代行为统计。Statistics of the behavior of the old and permanent generations.
gcoldcapacity
年老代行为统计。Statistics of the sizes of the old generation.
gcutil
垃圾回收统计概述(百分比)。Summary of garbage collection statistics.
printcompilation
HotSpot编译方法统计。HotSpot compilation method statistics.
 
jstat -class 77719
 
Loaded : 加载class的数量
Bytes : class字节大小
Unloaded : 未加载class的数量
Bytes : 未加载class的字节大小
Time : 加载时间
 
 
jstat -compiler 77719
 
Compiled : 编译数量
Failed : 编译失败数量
Invalid : 无效数量
Time : 编译耗时
FailedType : 失败类型
FailedMethod : 失败方法的全限定名
 
 
jstat -gc 77719
 
C即Capacity 总容量,U即Used 已使用的容量
S0C : survivor0区的总容量
S1C : survivor1区的总容量
S0U : survivor0区已使用的容量
S1C : survivor1区已使用的容量
EC : Eden区的总容量
EU : Eden区已使用的容量
OC : Old区的总容量
OU : Old区已使用的容量
MC  :  当前元空间的容量 (KB)
MU  : 元空间 的使用 (KB)
CCSC:  压缩类空间大小
CCSU:  压缩类空间使用大小
YGC : 新生代垃圾回收次数
YGCT : 新生代垃圾回收时间
FGC : 老年代垃圾回收次数
FGCT : 老年代垃圾回收时间
GCT : 垃圾回收总消耗时间
 
 
jstat -gccapacity 77719
 
NGCMN : 新生代占用的最小空间
NGCMX : 新生代占用的最大空间
OGCMN : 老年代占用的最小空间
OGCMX : 老年代占用的最大空间
OGC:当前年老代的容量 (KB)
OC:当前年老代的空间 (KB)
MCMN:元空间最小
MCMX:元空间最大
CCSMN: 压缩类最小空间
CCSMX: 压缩类最大空间
 
 
jstat -gccause 77719
 
LGCC:最近垃圾回收的原因
GCC:当前垃圾回收的原因
 
 
jstat - gcmetacapacity 77719
 
 
jstat -gcnew 77719
 
S0C:第一个幸存区大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
TT:对象在新生代存活的次数
MTT:对象在新生代存活的最大次数
DSS:期望的幸存区大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
 
 
jstat -gcnewcapacity 77719
 
 
jstat -gcold 77719
 
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
OC:老年代大小
OU:老年代使用大小
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
 
 
jstat - gcoldcapacity  77719
 
 
jstat -gcutil 77719
 
 
jstat -printcompilation 77719
Compiled:被执行的编译任务的数量
Size:方法字节码的字节数
Type:编译类型
Method:编译方法的类名和方法名。类名使用"/" 代替 "." 作为空间分隔符. 方法名是给出类的方法名. 格式是一致于HotSpot - XX:+PrintComplation 选项
 

 

三、jstack

jstack
 
用法一
 
直接
jstack 77719 
肉眼看是不是存在有问题的线程
 
用法二
 
当有线程卡主的时候
jstack -F 77719
查看哪个线程一直在执行或者死锁
 
用法三(很有用)
 
cpu占用高
先使用如下命令查询出哪个线程
ps p 77719 -L -o pcpu,pid,tid,time,tname,cmd
 
然后将线程号转为16进制
再用jstack 77719 |grep ’线程号’ 查询 (注意“线程号”大小写,线程里面可能有大小写区分)
 
死锁,Deadlock(重点关注)

执行中,Runnable

等待资源,Waiting on condition(重点关注)

等待获取监视器,Waiting on monitor entry(重点关注)

暂停,Suspended

对象等待中,Object.wait() 或 TIMED_WAITING

阻塞,Blocked(重点关注)

停止,Parked

 

四、jmap

1、jmap 77719
 
 
 
2、jmap  -histo:live 77719  |less
 
 
3、jmap  -clstats 77719
 
4. jmap -dump:format=b,file=heapdump.phrof 77719 
下载文件
 
 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值