Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Question about UI / non-UI listeners
Question about UI / non-UI listeners [message #780632] Wed, 18 January 2012 20:13 Go to next message
Sai Missing name is currently offline Sai Missing nameFriend
Messages: 25
Registered: March 2011
Junior Member
Hi everyone:

I wrote an eclipse plugin, and got many "invalid thread errors". I know that this error is caused by "accessing a GUI object from a non-UI thread", but am *really* confused on the huge volume of "EventListener"s sublclasses in eclipse. I was surprised to find some listeners are called from UI-thread, while others are called from non-UI thread.

For example,

AWTEventListener, IResourceChangeListener and IJobChangeListener all implement the EventListener interface. However, I found the call back method in AWTEventListener is always called by UI-thread, thus the object access code there do not need to be wrapped by sync/asyncExec. But the other two listeners (IResourceChangeListener, and IJobChangeListener) are often called by non-UI thread, if the call back there access some UI object, an invalid thread error becomes apparent.

My question is "which listeners will be called by UI/non-UI thread"? is there any rule for this? If not, do I need to remember (hardcode) those facts?

[I got some answers as follows:
If your non-UI based listener needs to call UI object, this call should happen using asyncExec or syncExec.
For the bigger part of your question, you may get a better answer in the 'Eclipse Platform' forums.

I am really interested in knowing what would be the UI/non-UI based listeners in Eclipse's platform.

thanks a lot, any suggestion is highly appreciated.

Re: Question about UI / non-UI listeners [message #782811 is a reply to message #780632] Tue, 24 January 2012 14:02 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 744
Registered: January 2012
Senior Member

I think you may be wrongly lumping AWT/Swing together with SWT -- they are distinct and cannot be mixed. SWT is completely independent of AWT and does not share any code. They each have their own UI thread.

Although SWT and AWT/Swing can co-exist (search for the SWT_AWT bridge), there are some caveats (search for Gordon Hirsch's article, though it's a bit out of date). You have to make sure you use the right UI thread, either through Display.asyncExec() for SWT or SwingUtilities.invokeLater() for AWT/Swing. If you are having to bridge between the SWT and AWT/Swing, then avoid the synchronous versions as it's a sure source of deadlocks.

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Question about UI / non-UI listeners [message #786600 is a reply to message #780632] Mon, 30 January 2012 16:10 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Usually it's up to the interface that allows the add*Listener(*) to specify if it's called on the UI thread. The default assumption is listeners can be called back on any worker thread ... except the services and framework provided by org.eclipse.ui. There the assumption should be that it is called on the UI thread *unless* the interface says otherwise.


Previous Topic:TabDescriptorProvider and tabbed.propertyTabs extension point
Next Topic:Eclipse hotkey for the mouse double click?
Goto Forum:

Current Time: Fri May 25 03:40:11 GMT 2018

Powered by FUDForum. Page generated in 0.01376 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top