(g_jvm)->AttachCurrentThread(&env, NULL) 后使用 (g_jvm)->DetachCurrentThread();程序报错

(g_jvm)->AttachCurrentThread(&env, NULL)  后使用 (g_jvm)->DetachCurrentThread();程序报错

ERROR: detaching thread with interp frames (count=13)

 

 

在java线程中不能使用AttachCurrentThread、DetachCurrentThread方法来获取JNIEnv。
调用DetachCurrentThread函数的地方在java线程中,即在java调用C++代码时在C++代码中调用了AttachCurrentThread方法来获取JNIEnv,此时JNIEnv已经通过参数传递进来,你不需要再次AttachCurrentThread来获取。在释放时就会报错。

 

int status;
JNIEnv *env;
bool isAttached = false;
status = g_jvm->GetEnv((void**)&env, JNI_VERSION_1_6);
if(status < 0)
{
  g_jvm->AttachCurrentThread(&env, NULL);//将当前线程注册到虚拟机中.
  isAttached = true;
}

env->CallVoidMethod(g_obj, receiveSendLogInInfo);

if(isAttached)
g_jvm->DetachCurrentThread();

posted @ 2016-04-05 14:36  莱纳·龙特  阅读(5485)  评论(0编辑  收藏  举报