Reputation: 4731
I have a Java program that at some point turns into 100% CPU usage and sleep state at the same time. The program is not multithreaded.
Looking around, I think the most likely cause for that is a bug or some mismatch in the way I run the java interpreter with respect to garbage collection. I can only think that the 100% CPU usage is because of GC. I am allocating enough memory for the program to run using Xmx, and the program does not run even near the amount I allocate. The amount I allocate is also much less than the total memory available on the machine.
I found this:
http://code.google.com/p/spymemcached/issues/detail?id=279
There were also some mentions of that on stackoverflow.com such as here:
CMS garbage collector - when does it run?
Still, I couldn't find a solution. Is this a bug in the JVM, and if so, how would I fix it?
EDIT: I added a paste of the jstack output here: http://pastebin.com/Au0V9FCN
Upvotes: 3
Views: 11938
Reputation: 621
Reproduce your issue, and when you see CPU is saturated perform JSTACK dumps on your Java process and use an OS utility to capture Process CPU and its threads CPU break down (ps -L in linux). You should actually setup a script that does this about 10 or 20 times 1 sec spaced samplings.
After this, if you are running on linux, you can cross reference the LWPid's with JSTACK output, just convert LWPID from ps -L to hex and you should be good to go on JSTACK's output.
At this point you will get a clear idea on what is consuming CPU on your app.
If GC is the problem then you will see the GC Threads hogging the CPU, at this point JConsole will be helpful in identifying further root cause. Otherwise you will notice clearly who is responsible for CPU consumption and you can act accordingly.
P.S. My examples are on linux, if you are not running linux you can google up ways to get process CPU break down dumps.
Do let me know what you find out.
Upvotes: 3