Sun Microsystems 2 Wireless Office Headset User Manual


 
6 Multitasking Guide May 2007
The following list summarizes the multitasking safety issues to consider when you
update or add native code for your port:
Multitask safety and multithread safety
Native global or static data
Singletons
Multitask Safety and Multithread Safety
Many systems today are multithreaded, which requires code that runs in these
systems to be thread safe or multithread safe. For example, POSIX Threads (Pthreads)
enables multiple native threads to run in the same OS process. Each native thread
has access to native memory, so any data structures in native memory must be
protected from concurrent access. This is typically accomplished through the use of
locks to provide mutual exclusion.
Similarly, multiple Java platform threads can run in the same Java virtual machine.
Each Java platform thread has access to the objects in the Java virtual machine, so
these objects must also be protected from concurrent access. Java code typically
accomplishes this through the use of synchronized code blocks or higher-level
constructs.
In the Java Wireless Client software, each task has one or more threads. Each of these
threads has concurrent access to the objects in that task, and so the same multithread
safety issues occur in Java Wireless Client software as in conventional Java virtual
machines. However, a thread in one task has access only to objects within its task,
and it has no access to objects in any other task. The multitasking nature of Java
Wireless Client software thus has no impact on the multithreaded safety of
applications.
All of the tasks in Java Wireless Client software run in a single OS process, and
therefore they all have access to the same native memory and data structures.
Threads from different tasks are scheduled arbitrarily. Therefore, native methods
that read or update native data structures must be prepared to deal with operations
from different tasks being interleaved in an arbitrary order. Furthermore, because
different tasks are generally running different applications, these different
applications are likely to place quite different demands on the underlying native
system.