Can JavaVM * and JNIEnv * be saved as a global variable and used elsewhere?

JavaVM * javaVM = NULL; JNIEnv * jniEnv = NULL;

(createJavaVM) (& javaVM, (void *) & jniEnv, & javaVMInitArgs)

where javaVM * and jniEnv * are global variables

+2


source to share


1 answer


Is it possible to save JavaVM * as a global variable and use it elsewhere?

Yes.



Can JNIEnv * be saved as a global variable and used elsewhere?

Not. This provides the context for a specific JNI method call. It depends on the current thread, the arguments of the current method, the local references that were created by the current method, all sorts of things, and it becomes invalid after the JNI method returns.

+4


source







All Articles