1、JNI异步条件下(多线程/回调函数),如何取得JNI Env
使用AttachCurrentThread()函数。
示例代码:
#ifdef JNI_VERSION_1_4
jint res = cached_jvm->AttachCurrentThread((void**)&env, NULL);
#else
jint res = cached_jvm->AttachCurrentThread(&env, NULL);
#endif;
if (env == NULL)
return;
jclass clsSctp = env->FindClass("com/sunrising/nettest/netpackage/implement/SCTPTransImplement");
if (clsSctp == NULL)
{
ThrowNullPointerException(env, "SCTP class is null");
cached_jvm->DetachCurrentThread();
return;
}
jmethodID mid = env->GetStaticMethodID(clsSctp, "communicationErrorNotify", "(JJ)V");
if (mid == 0) {
ThrowNullPointerException(env, "Method communicationErrorNotify() is null");
cache