java asyncexec_java – 使用syncExec()的SWT问题

博主在StackOverflow提出问题,其SWT应用中有进度条,用特定代码刷新。分析发现Runnable耗时恒定,但sShell.getDisplay().syncExec(progress)耗时不同。虽了解syncExec会使线程等待Runnable完成,但仍不明白为何耗时差异大,寻求指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是我在StackOverflow上的第一个问题(抱歉我的英文).我会尽力解释这个问题.

我有一个带有前景玉应用程序的swt应用程序,其中我有一个进度条来通知应用程序的持续时间.要刷新此进度条,我使用:

if(Display.getCurrent() != null) {

progress.run();

}

else {

sShell.getDisplay().syncExec(progress);

}

进展是:

Runnable progress = new Runnable() {

public void run () {

if (progressBar.isDisposed ())

return;

int percentage= (numStep*100)/maxSteps;

progressBar.setSelection(percentage);

if (numStep >= maxSteps){

label1.setText("The simulation has been completed.");

button.setEnabled(true);

}

}

};

我尝试分析这个Runnable所花费的时间并且它是常量,但是当我分析这一行时sSeh​​ll.getDisplay().syncExec(progress)需要不同的时间(从0ms到XXXXms)

我读过这个

syncExec(Runnable runnable) causes the current thread (if it is different than the user interface thread of the display) to wait for the runnable to finish.

但是Runnable是时间常数……

有人可以指导我吗?我不明白为什么有时需要3分钟和其他时间.

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值