Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 968
Chin Avatar asked May 07 '26 19:05

Chin


1 Answers

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.

like image 65
greg-449 Avatar answered May 10 '26 09:05

greg-449



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!