Java Reference
In-Depth Information
If you run this command on a single-CPU machine, much of the time you are unlikely to no-
tice that it is running. But if you attempt to start a new program, or time the performance of
another application, then you will certainly see the effect. Operating systems are good at
time-slicing programs that are competing for CPU cycles, but there will be less CPU avail-
able for the new program, and it will run more slowly. That experience sometimes leads
people to think it would be a good idea to leave some idle CPU cycles just in case something
else needs them.
But the operating system cannot guess what you want to do next; it will (by default) execute
everything it can rather than leaving the CPU idle.
Running a program whenever there are CPU cycles available maximizes the performance of that
program. There may be times you don't want that behavior. If, for example, you run SETI@home ,
it will consume all available CPU cycles on your machine. That may be fine when you aren't
working, or if you're just surfing the web or writing documents, but it could otherwise hamper
your productivity. (And let's not consider what might happen if you are playing a CPU-intensive
A number of operating-system-specific mechanisms can artificially throttle the amount of CPU
that a program uses—in effect, forcing the CPU to leave idle cycles just in case something might
want to take advantage of them. The priority of processes can also be changed so that those back-
ground jobs don't take CPU from what you want to run but still don't leave idle CPU cycles.
Those techniques are beyond the scope of our discussion (and for the record, SETI@home will let
you configure those; it won't really take up all the spare cycles on your machine unless you tell it
to do so).
Java and single-CPU usage
To return to the discussion of the Java application—what does periodic, idle CPU mean in
that case? It depends on the type of application. If the code in question is a batch-style ap-
plication where there is a fixed amount of work, you should never see idle CPU because
there is no work to do. Driving the CPU usage higher is always the goal for batch jobs, be-
cause it means the job will be completed faster. If the CPU is already at 100%, then you can
of course still look for optimizations that allow the work to be completed faster (while trying
also to keep the CPU at 100%).
Search WWH ::

Custom Search