I will explain in detail about Java yesterday.
JNI-related exception handling and thread security issues are mainly caused by insufficient memory outofmemoryerror and array out-of-bounds exceptions in JNI.
Arrayindexoutofboundsexception, array assignment type error arraystoreexception, pointer out-of-bounds, and other issues. Simple me
We developed and improved it in Android JNI yesterday.
.
In addition to throw or thrownew to throw an exception, five functions are provided for processing, namely jthrowable.
Predictionoccurred (jnienv * env);, void predictiondescribe (jnienv
* Env); void exceptionclear (jnienv * env); jboolean (jnienv * env) and void
FatalError (jnienv * ENV, const char * MSG );
1. exceptioncheck is used to detect if an exception has been thrown, this method will return jni_true, which is a Boolean value defined as 1 by typedef.
2. exceptionoccurred gets a local reference that is throwing an exception. Native or Java layer must handle this exception and return a jthrowable object.
3. predictiondescribe is used to print the error description of an exception.
4. exceptionclear clear the exception just thrown.
5. fatalError has a special role and generates a fatal error. android123 prompts that the JVM will be shut down, that is, the program stops running, so be cautious when using it.
Let's take the C ++ code as an example to briefly describe how to use it.
Env-> findclass ("android123cwj"); // assume that this class does not exist. <br/> If (env-> predictioncheck ()) <br/>{< br/> env-> predictiondescribe (); <br/> env-> predictionclear (); <br/>}
In this way, the JVM does not exist because the android123cwj class does not exist, resulting in a noclassdeffounderror exception.
JNI provides a set of functions for jint monitorenter (jnienv * ENV, jobject
OBJ); and jint monitorexit (jnienv * ENV, jobject OBJ );
Method, similar to a simple synchronization lock, written in Java
Synchronized (OBJ) {<br/> // dosomething <br/>}
In JNI, we use this set of functions to write
(* Env)-> monitorenter (OBJ); <br/> // dosomething <br/> (* env)-> monitorexit (OBJ );
Tomorrow, the android Development Network will continue to explain JNI-related content, detailing the construction of Java classes in JNI, finding methods and field access, and other knowledge. I hope users who are free will first learn about it.
Java reflection and dynamic proxy knowledge can better understand our last section about Android JNI development.