Chin Chin - 1 month ago 20
Java Question

Difference between invokeLater/invokeAndWait and asyncExec/syncExec

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()
?

Answer

Eclipse uses the SWT User Interface, this is a completely separate UI system from Swing. asyncExec()/syncExec() are part of the SWT system.

If you are writing an Eclipse RCP or plug-ins for Eclipse you should be writing SWT code.

SWT does provide a method of using Swing code but this should be a last resort.

Since they are totally different UI systems each with its own event loop invokeAndWait and syncExec are not interchangeable. It is very easy to get into a mess when there are two UI event loops running.

Comments