首页 > 其他 > 详细

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

时间:2016-04-05 16:03:46      阅读:2662      评论:0      收藏:0      [点我收藏+]

(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();

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

原文:http://www.cnblogs.com/fyqds/p/5354989.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!