共计 4184 个字符,预计需要花费 11 分钟才能阅读完成。
明天学习了《深刻了解 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
正文完