Originally posted by Sean Sullivan:
My company builds web applications using
IBM's Websphere application server.
Recently, we noticed that the CPU utilization on
our production server would spike from 20% to
99%
It was occurring at random times.
Initially, we did not know what was causing the problem.
First, we checked to see if this was a known problem with
IBM Websphere 3.5.4
We looked to see if there were any IBM "fixpacks" for this
type of thing.
Next, we checked the "known bugs" list for the JVM. We
found nothing relevant.
We installed the Websphere "Resource Analyzer" tool to see
if it would help.
We checked the JVM heap size and memory usage. It seemed normal.
We decided to get a thread dump from the JVM
Here are instructions for obtaining a thread dump:
http://www.weblogic.com/docs51/techsupport/threaddump.html http://access1.sun.com/technotes/00608.html http://developer.java.sun.com/developer/technicalArticles/Programming/Stackt race/
After creating a thread dump, we studied the output. We determined
that one of the threads was caught in an infinite loop.
The thread dump provided a snapshot of the thread's stack trace.
We inspected our application source code.
We found this code inside a method:
for (int i = 0; i < foo.size(); i++)
{
for (int j = 0; j < bar.size(); i++)
{
// code omitted
}
}
The bug is in the inner for loop. The original programmer
incorrectly used "i++" in the inner for loop.
This prevented the inner for loop from exiting.
After fixing this bug, the high CPU utilization
disappeared.