Sun Microsystems 2 Wireless Office Headset User Manual


 
Chapter 2 Multitasking Safety 19
These examples show how multitask safety can be achieved by judicious migration
of data from Java code into native code (for global singletons) and from native code
into Java code (for context-specific data). Some libraries have explicit context objects,
with all operations relative to that context object.
For cases like that, a reliable technique is to put the native context pointer into a
nativePtr int field in the Java object. In other cases, such as the microwave
library, the library maintains implicit context in its own static data. For these cases, it
is necessary for the code to create its own context. This context can be stored as
fields in the Java object itself, or a data structure can be allocated on the native heap
and a pointer to this structure placed into a nativePtr int field. Ensuring that the
context for all operations is relative to a Java object automatically provides multitask
safety.