1

我有一些线程消耗大量 CPU 并想找到它们。

我在一台linux机器上。苏塞。在使用 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)
4

1 回答 1

2

事实证明,所有这些线程都是垃圾收集线程。

我们的程序生成非常非常大的对象并保存在内存中。

当堆运行不足时,gc 线程将完成它们的工作。而且由于所有这些对象都在旧区域中,并且它们都无法释​​放,因此线程继续运行 FGC。

这就是cpu这么高的原因。

于 2013-09-28T03:02:09.380 回答