我有一些线程占用大量CPU并且想要找到它们。
我在linux机器上。 SUSE。使用top并打开线程时,它会显示消耗高cpu的线程:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ PPID COMMAND
28597 acrosspm 20 0 3682m 2.8g 23m R 99 4.4 128:51.01 28481 java
28593 acrosspm 20 0 3682m 2.8g 23m R 97 4.4 129:03.77 28481 java
28598 acrosspm 20 0 3682m 2.8g 23m R 97 4.4 129:12.65 28481 java
28600 acrosspm 20 0 3682m 2.8g 23m R 97 4.4 128:59.34 28481 java
28610 acrosspm 20 0 3682m 2.8g 23m R 97 4.4 129:18.72 28481 java
但是当我使用jstack -F 28481时,它与最繁忙的线程id不匹配。
我尝试使用jconsole和jvisualvm。他们都没有能够对线程数据进行采样,因为我认为jmx已经坏了(我可以在进程的CPU跳转到2000%之前通过jmx连接)
那么还有其他方法可以找出cpu消费线程的调用堆栈吗?
非常感谢。
线程转储的某些部分将是:
Thread 28641 "MSC service thread 1-2": (state = BLOCKED)
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Thread 28640 "MSC service thread 1-1": (state = BLOCKED)
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Thread 28638 "Reference Reaper": (state = BLOCKED)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007825b8268> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
- locked <0x00000007825b8268> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at org.jboss.modules.ref.References$ReaperThread.run(References.java:68)
VM Thread 28636 "Service Thread": (state = BLOCKED)
VM Thread 28635 "C1 CompilerThread14": (state = BLOCKED)
VM Thread 28634 "C1 CompilerThread13": (state = BLOCKED)
VM Thread 28633 "C1 CompilerThread12": (state = BLOCKED)
VM Thread 28632 "C1 CompilerThread11": (state = BLOCKED)
VM Thread 28631 "C1 CompilerThread10": (state = BLOCKED)
VM Thread 28630 "C2 CompilerThread9": (state = BLOCKED)
VM Thread 28629 "C2 CompilerThread8": (state = BLOCKED)
VM Thread 28628 "C2 CompilerThread7": (state = BLOCKED)
VM Thread 28627 "C2 CompilerThread6": (state = BLOCKED)
VM Thread 28626 "C2 CompilerThread5": (state = BLOCKED)
VM Thread 28625 "C2 CompilerThread4": (state = BLOCKED)
VM Thread 28624 "C2 CompilerThread3": (state = BLOCKED)
VM Thread 28623 "C2 CompilerThread2": (state = BLOCKED)
VM Thread 28622 "C2 CompilerThread1": (state = BLOCKED)
VM Thread 28621 "C2 CompilerThread0": (state = BLOCKED)
VM Thread 28620 "JDWP Event Helper Thread": (state = BLOCKED)
VM Thread 28619 "JDWP Transport Listener: dt_socket": (state = BLOCKED)
Thread 28618 "Signal Dispatcher": (state = BLOCKED)
Thread 28617 "Finalizer": (state = BLOCKED)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
- locked <0x0000000782459cf0> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189)
Thread 28616 "Reference Handler": (state = BLOCKED)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:125)
- waiting to lock <0x0000000781816e20> (a java.lang.ref.Reference$Lock)
答案 0 :(得分:2)
事实证明,所有这些线程都是垃圾收集线程。
我们的程序生成非常大的对象并保存在内存中。
当堆运行不足时,gc线程将完成它们的工作。由于所有这些对象都在旧区域,并且没有一个可以释放,因此线程继续运行FGC。
这就是为什么cpu如此之高。