Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java CPU resource hog, 100%

Tags:

java

cpu-usage

I have written a program which when it starts up runs about 96% CPU and then very quickly tips the CPU to 100% before crashing. I need to trace what is constantly being done by the CPU whether it is the program running though or a particular method or call being worked on.

Any suggestions or links?

Thanks.

like image 720
mhollander38 Avatar asked Jan 27 '26 20:01

mhollander38


2 Answers

Java VisualVM should help. It is a tool that is included in the standard JDK. It allows you to profile and inspect a running Java program. It should be in the same directory as your javac executable.

Here is a quick synopsis of the command line to use to invoke the tool.

like image 175
A. Levy Avatar answered Jan 29 '26 09:01

A. Levy


you can start with profiling your application.

As you have not mentioned the Java version therefore i am safely assuming SUN JDK 1.5.

For a starter you can use:

  1. http://jrat.sourceforge.net/ OR
  2. NetBeans IDE profiler for checking the bottle necks in your program.

Secondly, you can use JConsole for monitoring the memory usage in your application. Its in your <JDK HOME>\bin.

If you are using SUN JDK 1.6 then as A. Levy mentioned, use jvisualvm for CPU and Heap profiling.

And possible then post your code snippet.

like image 30
Favonius Avatar answered Jan 29 '26 08:01

Favonius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!