Java开发中可以防止界面假死的刷新代码
作者:李灿辉 时间:2023-11-23 22:23:41
代码如下:
try {
// 创建一个线程
Thread thread = new Thread() {
public void run() {
int i = 0;
while(true){
final long start = System.currentTimeMillis();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
final int a = i;
if (!Display.getDefault().isDisposed()) {
Runnable runnable = new Runnable() {
public void run() {
processModel.setProcessName(start + "---" + a);
}
};
Display.getDefault().syncExec(runnable);
}
i++;
}
}
};
thread.start();
} catch (Exception e) {
e.printStackTrace();
}
来源:https://blog.csdn.net/li_canhui/article/details/7057212
标签:java,thread,exception
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android 将view 转换为Bitmap出现空指针问题解决办法
2022-02-12 02:17:23
使用MAT进行JVM内存分析实例
2023-12-14 05:29:51
![](https://img.aspxhome.com/file/2023/8/103988_0s.png)
Android如何使用GestureDetector进行手势检测详解
2022-03-21 22:08:46
MyBatis多对多关联映射创建示例
2023-08-09 06:40:10
![](https://img.aspxhome.com/file/2023/0/128910_0s.jpg)
C#使用集合实现二叉查找树
2023-06-01 06:17:21
![](https://img.aspxhome.com/file/2023/3/83353_0s.png)
springboot添加https服务器的方法
2022-08-19 06:14:31
Android之日期时间选择控件DatePicker和TimePicker实例
2023-08-02 14:57:26
![](https://img.aspxhome.com/file/2023/1/93301_0s.png)
java基于包结构的请求路由实现实例分享
2021-10-23 13:10:18
解决Java导入excel大量数据出现内存溢出的问题
2023-05-30 08:41:20
RabbitMQ延迟队列及消息延迟推送实现详解
2023-11-15 15:31:31
![](https://img.aspxhome.com/file/2023/1/59001_0s.png)
详解SpringBoot配置连接池
2022-03-28 13:29:42
![](https://img.aspxhome.com/file/2023/8/105908_0s.png)
Flutter 队列任务的实现
2023-07-07 17:25:14
详细了解JAVA NIO之Buffer(缓冲区)
2022-08-18 00:59:28
![](https://img.aspxhome.com/file/2023/2/67482_0s.jpg)
C# 定时器保活机制引起的内存泄露问题解决
2022-09-19 00:31:33
Android中new Notification创建实例的最佳方法
2022-03-19 15:52:25
Android刮刮卡效果实现代码
2023-08-24 01:29:58
![](https://img.aspxhome.com/file/2023/2/138902_0s.gif)
Java实现通讯录管理系统项目
2022-11-17 02:41:03
![](https://img.aspxhome.com/file/2023/3/71903_0s.jpg)
android多线程断点下载-带进度条和百分比进度显示效果
2022-03-20 14:30:43
![](https://img.aspxhome.com/file/2023/4/91714_0s.png)
Android RIL使用详解
2021-09-30 18:06:45
![](https://img.aspxhome.com/file/2023/2/137182_0s.png)
Spring Data Jpa框架最佳实践示例
2021-11-25 00:43:01