Which Java thread is hogging the CPU?

前端 未结 12 1743
萌比男神i
萌比男神i 2020-12-07 07:48

Let\'s say your Java program is taking 100% CPU. It has 50 threads. You need to find which thread is guilty. I have not found a tool that can help. Currently I use the follo

12条回答
  •  不思量自难忘°
    2020-12-07 08:29

    An option you could consider is querying your threads for the answer from within application. Via the ThreadMXBean you can query CPU usage of threads from within your Java application and query stack traces of the offending thread(s).

    The ThreadMXBean option allows you to build this kind of monitoring into your live application. It has negligible impact and has the distinct advantage that you can make it do exactly what you want.

提交回复
热议问题