美文网首页小卜java
JAVA基础之虚拟机故障处理工具

JAVA基础之虚拟机故障处理工具

作者: 汤太咸啊 | 来源:发表于2021-11-23 17:14 被阅读0次
    今天学习了《深入理解java虚拟机》的故障处理工具,都是一些小命令,不复杂,只不过有些命令在prod环境不要使用,jmap这种,在动辄几G的内存的pod中,生成一次文件可能就导致了环境停止,这时如果还有大量请求进来,这个pod估计在生成dump文件之前就崩溃了。

    jps命令查看java进程

    buxuesongdeMacBook-Pro:~ buxuesong$ jps -l
    1121 /Users/buxuesong/Documents/git_code/account/account-api/target/account-api-1.3.0-SNAPSHOT.jar
    1131 sun.tools.jps.Jps
    buxuesongdeMacBook-Pro:~ buxuesong$ ps -ef|grep 1121
      501  1121  1120   0 11:01下午 ttys000    0:24.41 /usr/bin/java -jar /Users/buxuesong/Documents/git_code/account/account-api/target/account-api-1.3.0-SNAPSHOT.jar
      501  1138  1125   0 11:02下午 ttys001    0:00.00 grep 1121
    buxuesongdeMacBook-Pro:~ buxuesong$ 
    

    jstat命令用于监视虚拟机各种运行状态信息

    buxuesongdeMacBook-Pro:~ buxuesong$ jstat -gcutil 1121
      S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
      0.00  96.78  63.52  23.52  95.12  92.69     11    0.101     2    0.211    0.311
      //1121命令下,2个Survivor区(S0、S1,表示Survivor0、Survivor1),S0为空,S1占用96.78%,新生代Eden区(E,表示Eden)使用了63.52%
      //老年代(O,表示Old)和永久代(M)则分别使用了23.52%和95.12%的空间
      //CCS,压缩使用比例92.69%
      //程序运行以来共发生Minor GC(YGC,表示Young GC)11次,总耗时0.101秒;
      //发生Full GC(FGC,表示Full GC)2次,总耗时(FGCT,表示Full GCTime)为0.211秒;所有GC总耗时(GCT,表示GC Time)为0.311秒。
    

    jinfo命令实时查看和调整虚拟机各项参数

    buxuesongdeMacBook-Pro:~ buxuesong$ jinfo -flag CMSInitiatingOccupancyFraction 1835
    -XX:CMSInitiatingOccupancyFraction=-1
    

    jmap(Memory Map for Java)命令用于生成堆转储快照(一般称为heapdump或dump文件)

    buxuesongdeMacBook-Pro:~ buxuesong$ jmap -dump:format=b,file=account.dump 1868
    Dumping heap to /Users/buxuesong/account.dump ...
    Heap dump file created
    

    jhat(JVM Heap Analysis Tool)命令与jmap搭配使用,来分析jmap生成的堆转储快照。运行完毕后通过http://localhost:7000来访问查看dump内容

    buxuesongdeMacBook-Pro:~ buxuesong$ jhat account.dump 
    Reading from account.dump...
    Dump file created Wed Nov 25 23:37:23 CST 2020
    Snapshot read, resolving...
    Resolving 402521 objects...
    Chasing references, expect 80 dots................................................................................
    Eliminating duplicate references................................................................................
    Snapshot resolved.
    Started HTTP server on port 7000
    Server is ready.
    

    jstack(Stack Trace for Java)命令用于生成虚拟机当前时刻的线程快照(一般称为threaddump或者javacore文件)

    buxuesongdeMacBook-Pro:~ buxuesong$ jstack -l 1939
    2020-11-25 23:47:43
    Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode):
    
    "Attach Listener" #34 daemon prio=9 os_prio=31 tid=0x00007fbe7a496800 nid=0x9d03 waiting on condition [0x0000000000000000]
       java.lang.Thread.State: RUNNABLE
    
       Locked ownable synchronizers:
        - None
    
    "Druid-ConnectionPool-Destroy-205735257" #33 daemon prio=5 os_prio=31 tid=0x00007fbe77f6f800 nid=0x9f03 waiting on condition [0x0000700012133000]
       java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at com.alibaba.druid.pool.DruidDataSource$DestroyConnectionThread.run(DruidDataSource.java:2032)
    
       Locked ownable synchronizers:
        - None
    
    "Druid-ConnectionPool-Create-205735257" #32 daemon prio=5 os_prio=31 tid=0x00007fbe77a01800 nid=0xa003 waiting on condition [0x0000700012030000]
       java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000007aa5174d0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1948)
    
       Locked ownable synchronizers:
        - None
    
    "mysql-cj-abandoned-connection-cleanup" #31 daemon prio=5 os_prio=31 tid=0x00007fbe7a3cf000 nid=0x6703 in Object.wait() [0x0000700011f2d000]
       java.lang.Thread.State: TIMED_WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000797d2a1f0> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
        - locked <0x0000000797d2a1f0> (a java.lang.ref.ReferenceQueue$Lock)
        at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:85)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    
       Locked ownable synchronizers:
        - <0x0000000797d2cce0> (a java.util.concurrent.ThreadPoolExecutor$Worker)
    
    "DestroyJavaVM" #30 prio=5 os_prio=31 tid=0x00007fbe7c87f800 nid=0x1003 waiting on condition [0x0000000000000000]
       java.lang.Thread.State: RUNNABLE
    
       Locked ownable synchronizers:
        - None
    

    相关文章

      网友评论

        本文标题:JAVA基础之虚拟机故障处理工具

        本文链接:https://www.haomeiwen.com/subject/pyaitrtx.html