Sun Microsystems 2 Wireless Office Headset User Manual


 
5
CHAPTER
2
Multitasking Safety
The Java Wireless Client software provides the ability to run multiple MIDlets
concurrently in a single OS process. From the standpoint of the OS, there is one
process and one Java virtual machine. However, from the standpoint of a Java
application, it appears as if it is running in its own, independent virtual machine,
isolated from other Java applications.
These apparently independent virtual machines are called tasks. Each MIDlet runs in
its own task. When a new MIDlet is started, a new task is created for it. When a
MIDlet exits, its task is destroyed. The Application Management Software (AMS)
runs in a dedicated task, and it is running the entire time the Java Wireless Client
software is active.
Although tasks cannot interact (they cannot access each other’s objects, for example),
they do share native code, process resources, and external resources. This sharing
leads to some implementation issues, both in native code and in Java programming
language code (Java code). The Java Wireless Client software takes these issues into
account. Those who want to integrate existing libraries, which might not have been
written with multitasking in mind, also need to be aware of the issues so that they
can add the source code correctly.
Code integrated into the Java Wireless Client software must be multitask safe. That is,
it must maintain the independence of one task from another. Because tasks run in a
single operating system process, the OS process can run native code for any task. To
keep tasks from interfering with each other and with each other’s data, the code
must be made aware of the task on whose behalf it is being called and possibly
allocating resources. When the task context is established, the code is considered
multitask safe.
This chapter points out issues that might arise in ensuring native code is multitask
safe. It also provides techniques for making the code multitasking safe in different
situations.