thread
来源:互联网 发布:linux怎么解压war包 编辑:程序博客网 时间:2024/05/01 18:29
1.在线程的run方法中最好不要写太多耗时太多的程序
最好是循环调用该进程:
比如在android进度条中如果写下述代码:
public void run() {
// TODO Auto-generated method stub
while(i<80){
i+=10;
bar.setProgress(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
那么可能会导致进度条的值不是一秒一秒的递增,而是等待一段时间后值忽然增加到最大;
原因:个人觉得应该是在执行Thread.sleep(1000)这段代码是已经抛出异常导致执行时的问题;
应改进为:
public void run() {
// TODO Auto-generated method stub
if(i<80){
i+=10;
bar.setProgress(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO: handle exception
e.printStackTrace();
}
handler.post(thread);
}
}
这样反复调用就不会出现上述问题,可以在一定程度上使进度条每隔一秒钟更新一次;
- Thread
- thread
- Thread
- Thread
- thread
- thread
- Thread
- Thread
- Thread
- Thread
- Thread
- Thread
- Thread
- Thread
- Thread
- Thread
- Thread
- Thread
- 4.7 Proxy代理模式
- 7月24日
- spring+hibernate架构中Dao访问数据库的几种方法
- 程序员技术练级攻略
- linkflags += -Wl
- thread
- HDU2491 贪心
- How can I capture raw 802.11 frames, including non-data (management, beacon) frames?
- 静态链接(续)
- hdu1010(深搜 +剪枝)
- jsf中导入css文件
- 802.11成帧封装实现(二)
- C++ 面试题
- DataGridViewComboBoxCell设置值的注意事项