JNI

From miki
Revision as of 15:45, 21 September 2011 by Mip (talk | contribs) (→‎Frequent Caveats)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page is over JNI, The Java Native Interface.

Frequent Caveats

References:

  • Sheng Liang, The Java Native Interace — Programmer's Guide and Specification, Addison Wesley.


Don't cache JNIEnv between threads
Each thread gets its own value of JNIEnv
Don't truncate jboolean arguments
jboolean type is actually a 8-bit type, so value like 256/512 would actually be treated like false
Don't mix thread models (green thread vs native thread) if models are different
Cache field / Method ID at the time class is created
Better performance, and avoid using the wrong field/method if a sub-class that overrides some field/method is passed.