Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 669
I.Randanad Avatar asked Jun 01 '10 19:06

I.Randanad


People also ask

Is Java CPU intensive?

java, that repeats a work unit of finding all prime numbers in a given integer range. It is a good example of CPU intensive process. Many Java applications are using the multithreading technology to run multiple processes of the same type concurrently instead of running them sequentially.

What is JVM CPU usage?

A JVM may max out on CPU usage because of the incoming workload. The server capacity may not be sized sufficiently to handle the rate of requests coming in and in such a situation, the Java application may be doing work, trying to keep up with the workload.


2 Answers

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

like image 129
crowne Avatar answered Sep 22 '22 04:09

crowne


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.

like image 25
Uri Avatar answered Sep 22 '22 04:09

Uri