java asyncexec,Display类的syncExec()和asyncExec()之间的区别

在Eclipse插件项目中,使用Display类的syncExec()和asyncExec()方法来允许后台线程操作UI线程。syncExec()同步执行,后台线程等待运行结束;asyncExec()异步执行,后台线程不等待结果。选择使用取决于是否需要等待UI操作完成。例如,当需要立即更新UI时,应使用syncExec();而进行非阻塞任务时,适合使用asyncExec()。
摘要由CSDN通过智能技术生成

I'm working on a plugin project in which I'm using Eclipse background processing.

What's the difference between the syncExec() and asyncExec() methods of the Display class? In which situations are they applicable? Any example could be helpful.

解决方案

To allow background threads to perform operations on objects belonging to the UI-thread, the methods syncExec(Runnable runnable) and asyncExec(Runnable runnable) of Display are used. These are the only methods in SWT that can be called from any thread. They allow a runnable to be executed by the UI-thread, either synchronously, causing the background thread to wait for the runnable to finish, or asynchronously allowing the background thread to continue execution without waiting for the result. A runnable that is executed using syncExec() most closely matches the equivalent direct call to the UI operation because a Java method call always waits for the result before proceeding, just like syncExec().

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值