JNI
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.