JNI|在子线程中获得JNIEnv|AttachCurrentThread
A JNI interface pointer (JNIEnv*) is passed as an argument for each native function mapped to a Java method, allowing for interaction with the JNI environment within the native method.This JNI interface pointer can be stored, but remains valid only in the current thread. Other threads must first call AttachCurrentThread()to attach themselves to the VM and obtain a JNI interface pointer. Once attached, a native thread works like a regular Java thread running within a native method. The native thread remains attached to the VM until it callsDetachCurrentThread() to detach itself.[3]
void Call_Back_Invoke( void *user,int notify_id, unsigned int param )
{
bool isAttacked = false;
JNIEnv* env;
if(NULL == jni_tmpc.g_JVM)
{
LOGE("g_JVM == NULL");
return ;
}
int status = (jni_tmpc.g_JVM)->GetEnv((void **) &env, jni_tmpc.g_JNI_VERSION); if(status < 0) {
LOGD("callback_handler:failed to get JNI environment assuming native thread");
status = jni_tmpc.g_JVM->AttachCurrentThread(&env, NULL);
if(status < 0) {
LOGE("callback_handler: failed to attach current thread");
return;
}
isAttacked = true;
} switch( notify_id ){
case...
}
if(isAttacked) {
(jni_tmpc.g_JVM)->DetachCurrentThread();
}
LOGE("jni Call_Back_Invoke(1) notify_id = %d",notify_id );
}
JNI|在子线程中获得JNIEnv|AttachCurrentThread的更多相关文章
- 【转载】Delphi7从子线程中发送消息到主线程触发事件执行
在对数据库的操作时,有时要用一个子线程来进行后台的数据操作.比如说数据备份,转档什么的.在主窗口还能同是进行其它操作.而有时后台每处理一个数据文件,要向主窗口发送消息,让主窗口实时显示处理进度在窗口上 ...
- 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException: Can't create handler inside thread that has ...
- 如何在子线程中使用Toast和更新UI
因为没一个Looper处理消息循环,所以子线程中无法使用Toast 方法: Looper.prepare(); Toast.makeText(getActivity(),"刷到底啦" ...
- 在子线程中使用runloop,正确操作NSTimer计时的注意点 三种可选方法
一直想写一篇关于runloop学习有所得的文章,总是没有很好的例子.游戏中有一个计时功能在主线程中调用: 1 + (NSTimer *)scheduledTimerWithTimeInterval:( ...
- 让NSURLConnection在子线程中运行
可以有两个办法让NSURLConnection在子线程中运行,即将NSURLConnection加入到run loop或者NSOperationQueue中去运行. 前面提到可以将NSTimer手动加 ...
- iOS多线程的初步研究(五)-- 如何让NSURLConnection在子线程中运行
可以有两个办法让NSURLConnection在子线程中运行,即将NSURLConnection加入到run loop或者NSOperationQueue中去运行. 前面提到可以将NSTimer手动加 ...
- Android开发UI之在子线程中更新UI
转自第一行代码-Android Android是不允许在子线程中进行UI操作的.在子线程中去执行耗时操作,然后根据任务的执行结果来更新相应的UI控件,需要用到Android提供的异步消息处理机制. 代 ...
- Android开发之在子线程中使用Toast
在子线程中使用Toast的时候,出现Force close. 错误提示:Can't create handler inside thread that has not called Looper.pr ...
- Android利用Looper在子线程中改变UI
MainActivity如下: package cn.testlooper; import android.app.Activity; import android.os.Bundle; import ...
随机推荐
- c# json转Dictionary字典
JavaScriptSerializer s = new JavaScriptSerializer(); string jsonTexts = "{\"count\" ...
- 常用ASP函数的封装
做ASP开发常常需要用到一些小功能,这些功能通常我们都会封装成函数来使用,本教程提供了许多我们经常用到的ASP函数. <% '所有功能函数名如下: ' StrLength(str) 取得字符串长 ...
- 让aspx页面也可以通过url路由进行访问
参考文章:http://blog.csdn.net/zhanglong_longlong/article/details/8841030 这两天,在工作中需要将aspx的页面虚拟成url路径访问.比如 ...
- 【html】【21】高级篇--搜索框
下载: http://www.xwcms.net/js/bddm/25368.html 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- C# ACM poj1004
水题.. public static void acm1004(float[] a) { ; foreach (var item in a) { sum += item; } Console.Writ ...
- SVG实现描边动画
说起SVG,我是恨它又爱它,恨它是因为刚开始接触的时候自己傻B地想用代码去写它,其实在web上我们用它做交互也只是用了几个常用的特性而已,其他的标签知道这么一回事就成了,其实说白了它就是一种图片格式, ...
- 关于css中的align-content属性详解
align-content 作用: 会设置自由盒内部各个项目在垂直方向排列方式. 条件:必须对父元素设置自由盒属性display:flex;,并且设置排列方式为横向排列flex-direction:r ...
- 把URL传递参数转变成自定义实体方法
先定义下要获取的实体: public class InputClass { public long Id { get; set; } public int Status { get; set; } p ...
- Python3 内建模块 datetime/collections/base64/struct
datetime 我们先看如何获取当前日期和时间: >>> from datetime import datetime >>> now = datetime.now ...
- linux (centos 6.4)安装自定义分区方案(转载)
在计算机上安装 Linux 系统,对硬盘进行分区是一个非常重要的步骤,下面介绍几个分区方案. 方案 1 / :建议大小在 5GB 以上. swap :即交换分区,建议大小是物理内存的 1~2 倍. 方 ...