Difference between invokeLater/invokeAndWait and asyncExec/syncExec

时间:2016-10-20 13:19:34

标签: java swing concurrency eclipse-rcp

I am working on a project using Eclipse RCP and Swing. I see two pairs of methods invokeLater()/invokeAndWait() and asyncExec()/syncExec() being used a lot.

From what I understand, invokeLater()/invokeAndWait() belong to Swing, and asyncExec()/syncExec() belong to Eclipse. But what is the difference between these two pairs of methods?

If they are all used to execute a task on the UI thread, is it the same UI thread that they post the task onto? Are invokeLater() and asyncExec() interchangeable?

Is there any potential pitfall (e.g. deadlock, etc.) if I'm calling e.g. syncExec() from invokeAndWait()?

1 个答案:

答案 0 :(得分:2)

Eclipse使用SWT用户界面,这是一个与Swing完全独立的UI系统。 asyncExec()/syncExec()是SWT系统的一部分。

如果您正在为Eclipse编写Eclipse RCP或插件,那么您应该编写SWT代码。

SWT确实提供了一种使用Swing代码的方法,但这应该是最后的手段。

由于它们是完全不同的UI系统,每个系统都有自己的事件循环invokeAndWaitsyncExec不可互换。当有两个UI事件循环在运行时,很容易陷入混乱。