怎么通过java线程dump中的某一线程的状态或堆栈来确定此刻JVM正在做YongGC或FullGC等垃圾回收操作?
时间: 2023-12-06 19:45:37 浏览: 43
在Java线程dump文件中,我们可以通过查看某个线程的状态或堆栈信息来确定JVM是否正在进行垃圾回收操作。
首先,我们需要查看线程的状态。如果某个线程的状态为“GC”或“Gang worker”,则说明此时JVM正在进行垃圾回收操作。例如:
```
"GC task thread#0 (ParallelGC)" #13 prio=5 os_prio=0 tid=0x000000001f8f0800 nid=0x2d20 runnable "GC task thread#1 (ParallelGC)" #14 prio=5 os_prio=0 tid=0x000000001f8f2000 nid=0x1d08 runnable "Gang worker#0 (ParallelGC)" #15 prio=5 os_prio=0 tid=0x000000001f8f3000 nid=0x2b30 runnable "Gang worker#1 (ParallelGC)" #16 prio=5 os_prio=0 tid=0x000000001f8f4800 nid=0x2a20 runnable "Gang worker#2 (ParallelGC)" #17 prio=5 os_prio=0 tid=0x000000001f8f6000 nid=0x2e64 runnable
```
在上述线程状态信息中,可以看到存在“GC”和“Gang worker”的线程,因此可以确定JVM正在进行垃圾回收操作。
其次,我们可以查看线程的堆栈信息。如果堆栈信息中存在“G1FullGC”或“ParNew”等与垃圾回收相关的字眼,则说明此时JVM正在进行垃圾回收操作。例如:
```
"GC task thread#0 (ParallelGC)" prio=10 tid=0x00007f6a1c017800 nid=0x6f03 runnable "G1 Main Marker" prio=10 tid=0x00007f6a1c01a800 nid=0x6f04 waiting on condition [0x00007f6a12b8d000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x0000000799e1a5d8> (a com.sun.javafx.util.EventQueueSun$Latch) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215) at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1037) at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1328) at com.sun.javafx.util.EventQueueSun$Entry.waitForCompletion(EventQueueSun.java:433) at com.sun.javafx.util.EventQueueSun$LatchedRunnable.run(EventQueueSun.java:220) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at com.sun.javafx.util.EventQueueSun$11.run(EventQueueSun.java:248) at com.sun.javafx.util.EventQueueSun$11.run(EventQueueSun.java:247) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.util.EventQueueSun.lambda$null$1(EventQueueSun.java:247) at com.sun.javafx.util.EventQueueSun$$Lambda$175/1321556984.run(Unknown Source) 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) "G1 Conc#0" prio=10 tid=0x00007f6a1c010000 nid=0x6f02 runnable "VM Thread" os_prio=0 tid=0x00007f6a1c002000 nid=0x6efe runnable "GC Task Thread#0 (ParallelGC)" os_prio=0 tid=0x00007f6a1c011000 nid=0x6eff runnable "GC Task Thread#1 (ParallelGC)" os_prio=0 tid=0x00007f6a1c012800 nid=0x6f00 runnable "GC Task Thread#2 (ParallelGC)" os_prio=0 tid=0x00007f6a1c013800 nid=0x6f01 runnable "VM Periodic Task Thread" os_prio=0 tid=0x00007f6a1c030000 nid=0x6f0e waiting on condition
```
在上述堆栈信息中,可以看到存在“G1 Conc”和“ParallelGC”等字眼,因此可以确定JVM正在进行垃圾回收操作。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)