简体   繁体   中英

How to find CPU-intensive class in Java?

I have a big program in Java that uses multithreading. In some cases, the program starts using 100% of three cores of my eight core system. In normal use, the program use all cores at 1-2%. How can I find the class that's overloading cores?

使用与jdk-1.6.0_10捆绑在一起的jvisualvm等分析器

The best solution is to use a profiler - that's what they're built for, and there's a great one bundled with Java 6.

Another (far from being as ideal a solution) is to run your program in the Eclipse IDE (if that's what you use) in debug mode. You can then look at the running threads. IF a lot of them are suspended, the one that is not might be your culprit. Force it to break (from the toolbar) and you can see where it is. There are many chances that you'll find a clear loop or busy waiting.

使用分析器确定哪些线程正在使用所有CPU周期以及它们正在执行的方法。

如果您使用的是Eclipse,则可以使用TPTP分析工具

如果您要使用商业分析器路线,那么我建议使用Dynatrace

尝试进行线程转储(请参阅jps,jstack命令),然后查看执行的方法。

如果您使用的是基于UNIX的Java或某些版本的Linux,请使用Java查看DTrace。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM