I wrote a Java application for creating search indexes. When run, this application continuously utilizes almost 100% of CPU until it ends. This application performs lots of IO operations. I need to reduce its CPU usage to about 50-60% sacrificing speed (i.e., it is fine if it takes an extra 10-15 minutes to finish).
So far, I tried changing different Java HotSpot VM options but no success.
"ps -p PID -o pid,nlwp" shows me that the applications NLWP is 13.
Could any one offer advice regarding reducing CPU usage?
Why do you need to reduce the CPU utilisation? That sounds like a spurious requirement. What harm does 100% CPU utilisation do?
I guess that your real requirement is to avoid starving other applications of CPU. That's what process and thread priorities are for.
You can set the priority of your whole Java application process to be lower than other applications; that's what the "nice" or "renice" commands do for your on Unix (or Mac OS X). Alternatively, and I think nicer, you can start a reduced-priority thread within your application, to do the CPU-intensive work. Look at the API for java.lang.Thread, noting that you must set the thread priority before starting the thread.
Either way will mean that other applications always get priority use of the CPU. But, when they don't need it, your application takes up all the slack. This is much better than Thread.sleep(), where there will be periods when no application is using the CPU, which is just a waste of potential processing.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.