综合以前写的线程例子 演变成现在这个样子
具体的思路 跟上一个帖子没有什么变化,只是优化了点代码! 这里就不写注释了!
http://44289533.iteye.com/admin/blogs/1714483可能代码不是很周到,但是基本可以实现超时的问题,如果大家有更好的建议 不妨留下您的建议,咱们共同讨论一下! 感谢了!
我的Skype: chu_jingwei 初京蔚
注: handler switch case 3: 这个模块是在 数据访问层 假如出现SQLException 发送的消息a
private Thread threadA;
private Thread threadB;
private boolean isTimeOut;
private boolean isAllDone;
private boolean isStopThread;
isTimeOut = false;
isAllDone = false;
isStopThread = false;
showWaitDialogNoTitle(getString(R.string.MSG_I_0004));
//タイムアウトThread
threadA = new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
try {
Thread.sleep(CHECK_TIME);
if (!isAllDone && !isStopThread&&!Thread.interrupted()) {
isTimeOut = true;
threadB.interrupt();
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);
}
} catch (InterruptedException e) {
// e.printStackTrace();
}
Looper.loop();
}
});
threadA.setDaemon(true);
threadA.start();
//データの獲得Thread
threadB = new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
list = countListBll.getAllByJan(handler, productCD);//access DB
if (!isTimeOut && !isStopThread&&!Thread.interrupted()) {
isAllDone = true;
threadA.interrupt();
Message msg = new Message();
msg.what = 2;
handler.sendMessage(msg);
}
Looper.loop();
}
});
threadB.start();
} else {
// is not net work
if (!currentDialog.isShowing()) {
String msg = getString(R.string.MSG_E_0003);
String okStr = getString(R.string.MSG_COMMON_OK);
showAlertDialog_OK(msg, okStr,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
stopThread();
finish();
}
});
}
}
/**
* Threadを閉める
*/
private void stopThread() {
if (threadA != null) {
threadA.interrupt();
}
if (threadB != null) {
threadB.interrupt();
}
}
/**
* UI更新Handler
*/
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
if (isTimeOut && !isAllDone) {
Log.i("====", ">>>>>>TimeOut");
String msgStr = getString(R.string.MESSAGE_CODE_U0014);
String okStr = getString(R.string.MSG_COMMON_OK);
showAlertDialog_OK(msgStr, okStr,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
lv_detial.setAdapter(null);
}
});
}
break;
case 2:
if (isAllDone && !isTimeOut) {
initListView();
}
break;
case 3:
// object has benn closed
isStopThread = true;// stop threadA threadB
stopThread();
String msgStr = getString(R.string.MSG_E_0003);
String okStr = getString(R.string.MSG_COMMON_OK);
showAlertDialog_OK(msgStr, okStr,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
stopThread();
finish();
}
});
break;
}
super.handleMessage(msg);
}
};
分享到:
相关推荐
BitTiger_Training_Jingwei(李经伟) 用于培训和家庭作业
BruceBlog程序源码(采用NHibernate) 博客程序是一个单用户博客程序,基于Asp.net技术 使用了ORM数据持久框架NHibernate 使用最简单的Access文件数据库(App_Data下为Access数据库文件)开发完成的 ...
源代码在这里:http://download.csdn.net/detail/jingwei12345/3762336
#资源达人分享计划#
SQLCA.Database = "jingwei" SQLCA.LogPass ="" SQLCA.ServerName = "www.hzjingwei.gov.cn" SQLCA.LogId = "sa" SQLCA.AutoCommit = False SQLCA.DBParm = "" connect using sqlca; close(d_splash) if sqlca....
author = {Wang, He and Sridhar, Srinath and Huang, Jingwei and Valentin, Julien and Song, Shuran and Guibas, Leonidas J.}, title = {Normalized Object Coordinate Space for Category-Level 6D Object ...
图像细化的matlab原始码经纬 经纬是一个开放源代码测试平台,用于评估图像标签分配,标签优化和基于标签的图像检索方法。 它是作为的一部分开发的,旨在及时反映该领域的最新技术。 依存关系 和和。...
群智能算法求解特征选择问题
matlab图片叠加的代码ObjectNet3D_toolbox 由斯坦福大学CVGL的Yu ...Jingwei and Choy, Christopher and Su, Hao and Mottaghi, Roozbeh and Guibas, Leonidas and Savarese, Silvio}, title = {ObjectNet3D:
源代码在这里:http://download.csdn.net/detail/jingwei12345/3762336
“”的实现(EMNLP 2015)。 免责声明:此研究代码令人讨厌,缺乏适当的设计或... 如果您将C-LDA / C-HDP用于研究目的,请使用以下引用: @InProceedings{zhang-EtAl:2015:EMNLP2, author = {Zhang, Jingwei and Ger
超越类条件假设:对抗依赖于... author={Chen, Pengfei and Ye, Junjie and Chen, Guangyong and Zhao, Jingwei and Heng, Pheng-Ann}, journal={arXiv preprint arXiv:2012.05458}, year={2020} } 0. 要求 Python
matlab图片叠加的代码ObjectNet3D_toolbox 由斯坦福大学CVGL的Yu ...Jingwei and Choy, Christopher and Su, Hao and Mottaghi, Roozbeh and Guibas, Leonidas and Savarese, Silvio}, title = {ObjectNet3D:
author={Chen, Pengfei and Ye, Junjie and Chen, Guangyong and Zhao, Jingwei and Heng, Pheng-Ann}, journal={arXiv preprint arXiv:2012.04193}, year={2020} } 在对角主导类条件标签噪声下,主要结论如下。 ...
也许有的同学已经注意到了,当我创建完“jingwei”这个对象时,这个对象的所有的属性都是空的,也就是说:这个对象的姓名是未定的、年龄是未定的、性别是未定的、薪水是未定的、午餐也是未定的。而我们想把这些属性...
C++自己写了很久都弄混几个常见的错误,堆 栈,托JingWei和Xiaoma的指导终于弄清楚,果然是工作几年的大牛不一样。呵呵。 直入主题。 C++中,局部函数里面,new一个内存块,地址是在堆中,而其他的变量基本...
逻辑回归matlab代码SAGA / ProxSVRG的局部收敛行为 Matlab代码重现论文结果 ,,,2018 Prox-SGD没有歧管标识 当非退化条件失败时 解决方案及其双重 支持识别三个不同的初始点 稀疏逻辑回归 ...Jingwei
protobuf-3.5.2,可直接解压就能用!开源框架定义的工具包
1.首先先把NFC读卡器驱动安装好,打开M1卡服务程序也就是解密IC卡的软件把好用的卡... 2.把自己的电梯卡拿走,放入特种UID卡 然后打开UID复制软件,导入刚才生成的dump文...
Flex 4 Cookbook 英文版( pdf 非影印版)