Sun Microsystems 2 Wireless Office Headset User Manual


 
Chapter 4 Other Multitasking Issues 31
Default CPU Scheduling Policy
By default, the Java Wireless Client software permits background applications to
have some CPU time. A background application can also interrupt the foreground
application under some circumstances.
Specifically, the CPU scheduling policy is fair share, which gives a higher proportion
of the CPU to the foreground application. Background applications can still run, but
their threads are scheduled less frequently.
This policy is implemented in the setForegroundMIDlet() method of the
MIDletProxyList class. The MIDlet being put into the background is given
minimal priority by calling the minPriority() method. The MIDlet being brought
into the foreground is given normal priority by calling the normalPriority()
method.
Alternative Policies and Their Implementations
One alternative to giving limited CPU access to background applications is to give
the CPU exclusively to the foreground application. This might provide better
interactive performance on systems with slow CPUs. It can also be good for some
applications, such as a game that displays graphics continually and requires
constant user input. This type of application probably needs to be frozen when in
background. The user loses the game if the game is placed into the background and
still allowed to use the CPU.
On the other hand, a device that freezes background MIDlets cannot run service or
daemon applications that do not interact with the user at all. An example of such an
application is a MIDlet that listens on the network for information about critical
system software updates.
Another alternative to the default fair-use policy is an open-for-competition policy,
that gives all applications equal priority, whether they are in the foreground or
background.
To implement an open-for-competition policy for the CPU, modify the contents of
the minPriority() and normalPriority() methods of the MIDletProxyUtils
class so that they do nothing, instead of changing the tasks’ priorities or suspending
or resuming them.
As you consider CPU policies, keep in mind that they interact with other policies for
background MIDlets. For example, the policy interacts with your decisions on
whether a background application is informed of its state change through a call to
the pauseApp method, or whether it has access to shared resources such as sound. A
uniform, correct answer does not exist.