文章目录
1. 概要
JDK内置工具
内置工具包括了JDK中提供的常用监控工具以及故障排查工具,主要包括了:
监控工具:包括
● jps
● jstat
故障排查工具,包括
● jinfo
● jmap
● jstack
● jhat
● jhsdb
可视化工具,包括:
● jhsdb
● iconsole
● VisualVM
● Java Mission Control
第三方工具
● Memory Analyzer Tool
2. JPS
jps全程:Java Virtual Machine Process Status Tool,用来查看JVM进程状态。
jps命令可以查看到系统中所有的java进程
现在linux环境,通过java -jar 启动了项目xxxx.jar
[root@node4 ~]#
jps
4305 Jps
2106 jar
[root@node4 ~]#jps -m
8137 Jps -m
2106 jar
[root@node4 ~]#jps -v
2106 jar
8508 Jps -Dapplication.home=/usr/java/jdk1.8.0_131 -Xms8m
[root@node4 ~]#jps -V
2106 jar
10655 Jps
[root@node4 ~]#jps -m -l -v
11410 sun.tools.jps.Jps -m -l -v -Dapplication.home=/usr/java/jdk1.8.0_131 -Xms8m
2106 dcits_scsw-raw.jar
[root@node4 ~]#
[root@node4 ~]#
ps -ef |grep java
root 2106 1392 2 17:39 pts/0 00:00:12 java -jar dcits_scsw-raw.jar
root 14290 3821 0 17:46 pts/2 00:00:00 grep --color=auto java
jps连接远程服务器
3. jstat—性能分析
jstat :JVM Statistics Monitoring Tool ,用于监控JVM的各种运行状态
主要利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收状况的监控。
[root@node4 ~]# jstat -gc -t 2106 1000 10
Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
1137.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1138.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1139.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1140.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1141.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1142.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1143.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1144.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1145.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
1146.4 1280.0 1280.0 640.8 0.0 10240.0 2435.1 25512.0 21063.5 52224.0 49462.9 6656.0 6203.2 170 0.447 2 0.092 0.538
[root@node4 ~]#
jstat 的用法
[root@node4 ~]# jstat -help
Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
option: 参数选项
-t: 可以在打印的列加上Timestamp列,用于显示系统运行的时间
-h: 可以在周期性数据数据的时候,可以在指定输出多少行以后输出一次表头
vmid: Virtual Machine ID( 进程的 pid)
interval: 执行每次的间隔时间,单位为毫秒
count: 用于指定输出多少次记录,缺省则会一直打印
常看options的种类
[root@node4 ~]# jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation
[root@node4 ~]#
● -class 显示ClassLoad的相关信息;
● -compiler 显示JIT编译的相关信息;
● -gc 显示和gc相关的堆信息;
● -gccapacity 显示各个代的容量以及使用情况;
● -gcmetacapacity 显示metaspace的大小
● -gcnew 显示新生代信息;
● -gcnewcapacity 显示新生代大小和使用情况;
● -gcold 显示老年代和永久代的信息;
● -gcoldcapacity 显示老年代的大小;
● -gcutil 显示垃圾收集信息;
● -gccause 显示垃圾回收的相关信息(通-gcutil),同时显示最后一次或当前正在发生的垃圾回收的诱因;
● -printcompilation 输出JIT编译的方法信息;
4. jmap–堆内存分析
jmap全程java memory map,用来展示对象内存映射或内存详情信息。
[root@node4 ~]# jmap -help
Usage:
jmap [option] <pid>
(to connect to running process)
jmap [option] <executable <core>
(to connect to a core file)
jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
<none> to print same info as Solaris pmap
-heap to print java heap summary
-histo[:live] to print histogram of java object heap; if the "live"
suboption is specified, only count live objects
-clstats to print class loader statistics
-finalizerinfo to print information on objects awaiting finalization
-dump:<dump-options> to dump java heap in hprof binary format
dump-options:
live dump only live objects; if not specified,
all objects in the heap are dumped.
format=b binary format
file=<file> dump heap to <file>
Example: jmap -dump:live,format=b,file=heap.bin <pid>
-F force. Use with -dump:<dump-options> <pid> or -histo
to force a heap dump or histogram when <pid> does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J<flag> to pass <flag> directly to the runtime system
参数:
● option: 选项参数。
● pid: 需要打印配置信息的进程ID。
● executable: 产生核心dump的Java可执行文件。
● core: 需要打印配置信息的核心文件。
● server-id 可选的唯一id,如果相同的远程主机上运行了多台调试服务器,用此选项参数标识服务器。
● remote server IP or hostname 远程调试服务器的IP地址或主机名。
option
● no option: 查看进程的内存映像信息,类似 Solaris pmap 命令。
● heap: 显示Java堆详细信息
● histo[:live]: 显示堆中对象的统计信息,如果指定了live子选项,则仅统计活动对象
● clstats:连接到正在运行的进程,并打印java堆的类加载器统计信息
● finalizerinfo: 显示在F-Queue队列等待Finalizer线程执行finalizer方法的对象
● dump::连接正在运行的进程,并转储java堆。其中dump_options的取值为:
live:指定时,仅Dump活动对象;如果没有指定,则转储堆中所有对象;
format=b:以hprof格式dump堆
file=filename:将hprof格式dump堆
● F: 当-dump没有响应时,使用-dump或者-histo参数. 在这个模式下,live子参数无效.
● help:打印帮助信息
● J:指定传递给运行jmap的JVM的参数
4.1 打印java堆详情
jmap -heap 进程号
root@node4 ~]# jmap -heap 2106
Attaching to process ID 2106, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.131-b11
using thread-local object allocation.
Mark Sweep Compact GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 482344960 (460.0MB)
NewSize = 10485760 (10.0MB)
MaxNewSize = 160759808 (153.3125MB)
OldSize = 20971520 (20.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 11796480 (11.25MB)
used = 3440392 (3.2810134887695312MB)
free = 8356088 (7.968986511230469MB)
29.164564344618057% used
Eden Space:
capacity = 10485760 (10.0MB)
used = 2784216 (2.6552352905273438MB)
free = 7701544 (7.344764709472656MB)
26.552352905273438% used
From Space:
capacity = 1310720 (1.25MB)
used = 656176 (0.6257781982421875MB)
free = 654544 (0.6242218017578125MB)
50.062255859375% used
To Space:
capacity = 1310720 (1.25MB)
used = 0 (0.0MB)
free = 1310720 (1.25MB)
0.0% used
tenured generation:
capacity = 26124288 (24.9140625MB)
used = 21569056 (20.569854736328125MB)
free = 4555232 (4.344207763671875MB)
82.56323004860458% used
20746 interned Strings occupying 1868696 bytes.
[root@node4 ~]#
4.2 打印堆中对象的统计信息
root@node4 ~]# jmap -histo:live 2106
num #instances #bytes class name
----------------------------------------------
1: 53033 5167240 [C
2: 10671 2954568 [I
3: 52558 1261392 java.lang.String
4: 9466 1062992 java.lang.Class
5: 11865 1044120 java.lang.reflect.Method
6: 28138 900416 java.util.concurrent.ConcurrentHashMap$Node
7: 3942 746584 [B
8: 8330 492648 [Ljava.lang.Object;
9: 11172 446880 java.util.LinkedHashMap$Entry
10: 5223 445600 [Ljava.util.HashMap$Node;
11: 12892 412544 java.util.HashMap$Node
12: 15825 372472 [Ljava.lang.Class;
13: 20865 333840 java.lang.Object
14: 154 315368 [Ljava.util.concurrent.ConcurrentHashMap$Node;
15: 4300 240800 java.util.LinkedHashMap
16: 2133 153576 java.lang.reflect.Field
17: 2775 133200 java.util.HashMap
4.3 dump出堆内存信息
[root@node4 ~]# jmap -dump:live,format=b,file=mydump.hprof 2106
Dumping heap to /root/mydump.hprof ...
Heap dump file created
4.4 触发java堆dump的方式
例如
当在linux中输入
kill -3 pid 命令后
java项目的后台日志就会打印堆信息
[DEBUG] 2022-10-14 18:28:38,548 method:org.mortbay.log.Slf4jLog.debug(Slf4jLog.java:49)
PWC5964: Scratch dir for the JSP engine is: /tmp/tomcat.80.6212897043698180701/work/Tomcat/localhost/scsw
[DEBUG] 2022-10-14 18:28:38,560 method:org.mortbay.log.Slf4jLog.debug(Slf4jLog.java:49)
PWC5966: IMPORTANT: Do not modify the generated servlets
2022-10-14 18:28:38.563 INFO 25654 --- [ main] o.s.b.w.e.t.TomcatWebServer : Tomcat started on port(s): 80 (http) with context path '/scsw'
2022-10-14 18:28:38.591 INFO 25654 --- [ main] c.d.s.ScswApplication : Started ScswApplication in 8.865 seconds (JVM running for 11.549)
2022-10-14 18:29:24
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode):
"DestroyJavaVM" #25 prio=5 os_prio=0 tid=0x00007f0f70008800 nid=0x6437 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"http-nio-80-Acceptor" #24 daemon prio=5 os_prio=0 tid=0x00007f0f70d07800 nid=0x6580 runnable [0x00007f0f3dd93000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250)
- locked <0x00000000e3e17ba0> (a java.lang.Object)
at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:546)
at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:79)
at org.apache.tomcat.util.net.Acceptor.run(Acceptor.java:129)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-Poller" #23 daemon prio=5 os_prio=0 tid=0x00007f0f70ce7000 nid=0x657d runnable [0x00007f0f3de94000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x00000000e3e17dd8> (a sun.nio.ch.Util$3)
- locked <0x00000000e3e17de8> (a java.util.Collections$UnmodifiableSet)
- locked <0x00000000e3e17d90> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioEndpoint$Poller.run(NioEndpoint.java:807)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-10" #22 daemon prio=5 os_prio=0 tid=0x00007f0f70d0c800 nid=0x6579 waiting on condition [0x00007f0f3df95000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-9" #21 daemon prio=5 os_prio=0 tid=0x00007f0f70d2b000 nid=0x6577 waiting on condition [0x00007f0f3e096000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-8" #20 daemon prio=5 os_prio=0 tid=0x00007f0f70d18000 nid=0x6575 waiting on condition [0x00007f0f3e197000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-7" #19 daemon prio=5 os_prio=0 tid=0x00007f0f70d43800 nid=0x6572 waiting on condition [0x00007f0f3e298000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-6" #18 daemon prio=5 os_prio=0 tid=0x00007f0f70b72000 nid=0x656f waiting on condition [0x00007f0f3e399000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-5" #17 daemon prio=5 os_prio=0 tid=0x00007f0f70b0f800 nid=0x656c waiting on condition [0x00007f0f3e49a000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-4" #16 daemon prio=5 os_prio=0 tid=0x00007f0f70cd7800 nid=0x6569 waiting on condition [0x00007f0f3e59b000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-3" #15 daemon prio=5 os_prio=0 tid=0x00007f0f70d08800 nid=0x6567 waiting on condition [0x00007f0f3e69c000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-2" #14 daemon prio=5 os_prio=0 tid=0x00007f0f70736000 nid=0x6565 waiting on condition [0x00007f0f3e79d000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"http-nio-80-exec-1" #13 daemon prio=5 os_prio=0 tid=0x00007f0f7073b800 nid=0x6564 waiting on condition [0x00007f0f3e89e000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e3e17fa8> (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 java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:146)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1114)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"container-0" #12 prio=5 os_prio=0 tid=0x00007f0f70b81000 nid=0x6523 waiting on condition [0x00007f0f3f19f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:563)
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer$1.run(TomcatWebServer.java:197)
"Catalina-utility-2" #11 prio=1 os_prio=0 tid=0x00007f0f70b88000 nid=0x651a waiting on condition [0x00007f0f3f2a0000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000eda6ea68> (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 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1088)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"Catalina-utility-1" #10 prio=1 os_prio=0 tid=0x00007f0f70b55000 nid=0x6519 waiting on condition [0x00007f0f3f3a1000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000eda6ea68> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
"Service Thread" #7 daemon prio=9 os_prio=0 tid=0x00007f0f70100800 nid=0x643e runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C1 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f0f700fd800 nid=0x643d waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f0f700fb800 nid=0x643c waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f0f700e9000 nid=0x643b waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f0f700a0800 nid=0x643a in Object.wait() [0x00007f0f6023c000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000000ece25f70> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f0f7009b800 nid=0x6439 in Object.wait() [0x00007f0f6033d000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
- locked <0x00000000ece26128> (a java.lang.ref.Reference$Lock)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"VM Thread" os_prio=0 tid=0x00007f0f70094000 nid=0x6438 runnable
"VM Periodic Task Thread" os_prio=0 tid=0x00007f0f70106000 nid=0x643f waiting on condition
JNI global references: 1458
Heap
def new generation total 11584K, used 6543K [0x00000000e3400000, 0x00000000e4090000, 0x00000000ecd50000)
eden space 10304K, 55% used [0x00000000e3400000, 0x00000000e399b878, 0x00000000e3e10000)
from space 1280K, 62% used [0x00000000e3e10000, 0x00000000e3ed8590, 0x00000000e3f50000)
to space 1280K, 0% used [0x00000000e3f50000, 0x00000000e3f50000, 0x00000000e4090000)
tenured generation total 25564K, used 18193K [0x00000000ecd50000, 0x00000000ee647000, 0x0000000100000000)
the space 25564K, 71% used [0x00000000ecd50000, 0x00000000edf147d0, 0x00000000edf14800, 0x00000000ee647000)
Metaspace used 40811K, capacity 43092K, committed 43392K, reserved 1087488K
class space used 5229K, capacity 5652K, committed 5760K, reserved 1048576K
4.5 启动jar,内存溢出的时候dump堆信息
java -jar -XX:+HeapDumpOnOutOfMemoryError xxxxx.jar
5. jstack–线程栈分析
jstack:Stack Trace for Java,用于打印当前虚拟机的线程快照(线程UK爱找也叫Thread Dump或者javacore文件)。
jstack 打印线程快照,而jmap打印内存快照,一般我们会结合使用
jstack -help
[root@node4 ~]# jstack -help
Usage:
jstack [-l] <pid>
(to connect to running process)
jstack -F [-m] [-l] <pid>
(to connect to a hung process)
jstack [-m] [-l] <executable> <core>
(to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack <pid> does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
[root@node4 ~]#
例如jstack -F 进程号
[root@node4 ~]# jstack -F 1477
Attaching to process ID 1477, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.131-b11
Deadlock Detection:
No deadlocks found.
Thread 3039: (state = BLOCKED)
Thread 1478: (state = BLOCKED)
Thread 1789: (state = IN_NATIVE)
- sun.nio.ch.ServerSocketChannelImpl.accept0(java.io.FileDescriptor, java.io.FileDescriptor, java.net.InetSocketAddress[]) @bci=0 (Interpreted frame)
- sun.nio.ch.ServerSocketChannelImpl.accept(java.io.FileDescriptor, java.io.FileDescriptor, java.net.InetSocketAddress[]) @bci=4, line=422 (Interpreted frame)
- sun.nio.ch.ServerSocketChannelImpl.accept() @bci=130, line=250 (Interpreted frame)
- org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept() @bci=4, line=546 (Interpreted frame)
忽略。。。。
当显示没有发现No deadlocks found.,就说明没有死锁
5.1 查看某java进程中的线程数
参考:https://blog.csdn.net/weixin_67470255/article/details/125071734
cat /proc/{pid}/status
其中Treads 后面的参数就是线程数
也可以grep一下,例如
[root@node4 ~]# jps -vml | grep dcits_scsw-raw.jar
1477 dcits_scsw-raw.jar -XX:+HeapDumpOnOutOfMemoryError
[root@node4 ~]#
如下1477是进程号
[root@node4 ~]# cat /proc/1477/status |grep Threads
Threads: 26
[root@node4 ~]#
5.2 查看每个线程的栈大小
默认jvm中,栈的大小是多少
[root@node4 ~]# java -XX:+PrintFlagsFinal -version | grep ThreadStackSize
intx CompilerThreadStackSize = 0 {pd product}
intx ThreadStackSize = 1024 {pd product}
intx VMThreadStackSize = 1024 {pd product}
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[root@node4 ~]#
查看linux操作系统的栈大小
[root@node4 ~]# ulimit -s
8192
参考了解
不显式设置-Xss或-XX:ThreadStackSize时,在Linux x64上ThreadStackSize的默认值就是1024KB,
给Java线程创建栈会用这个参数指定的大小。
如果把-Xss或者-XX:ThreadStackSize设为0,就是使用“系统默认值”。而在Linux x64上HotSpot VM给
Java栈定义的“系统默认”大小也是1MB。
所以这个条件下普通Java线程的默认栈大小怎样都是1MB。
至于操作系统栈大小(ulimit -s):这个配置只影响进程的初始线程;后续用pthread_create创建的线程都可
以指定栈大小。HotSpot VM为了能精确控制Java线程的栈大小,特意不使用进程的初始线程
(primordial thread)作为Java线程。
线程数量=(机器本身可用内存-JVM分配的堆内存)/Xss的值,比如我们的容器本身大小是8G,堆大小是
4096M,走-Xss默认值(1M),可以得出 最大线程数量:4096个。
原文链接:https://blog.csdn.net/qq_35676427/article/details/105570024
那我们程序中,每个线程的栈占了多少空间
5.4 将栈信息导出到文件中
jstack -l 1477 > my.log