How to find CPU-intensive class in Java? How to find CPU-intensive class in Java? multithreading multithreading

How to find CPU-intensive class in Java?


Use a profiler such as the jvisualvm that is bundled with jdk-1.6.0_10


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.


Use a profiler to figure out which thread(s) are using all of your CPU cycles, and the method(s) they are executing.