Is it ok to save JavaVM * and JNIEnv * as a global

2019-02-19 11:11发布

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

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

where javaVM * and jniEnv * are global variables

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-19 11:45

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

Yes.

Is it ok to save JNIEnv * as a global variable and use it elsewhere?

No. That represents a context for a specific JNI method invocation. It is dependent on the current thread, the arguments to the current method, the local references that have been created by the current method, all sorts of things, and it becomes invalid once that JNI method returns.

查看更多
登录 后发表回答