Eclipse beginner threading question...

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Eclipse beginner threading question...

Horst Heistermann
Hi,

 I am new to eclipse and I am having a problem with threads. I have
created a MultiPageEditorPart
editor. I have a background thread listening to model changes in my
application. I am notified of these changes
in a non -gui thread. I want to set MultiPageEditorPart as dirty
whenever I receive a model change event.
So I wrote a function like this

public void setEditorModified() {
       m_bModified = true;
       if (!super.isDirty()) {
           firePropertyChange(IEditorPart.PROP_DIRTY);
       }
   }


This method crashes whenever I call it from the background thread. Below
is the error stack. But it is a bit misleading. From the debugger, I can
see the issue is with the thread I am calling firePropertyChange() from.
Can anyone tell me what is the proper  way to update the dirty state
from a background thread. Also, the background thread is not aware of
the GUI components it only has a refer.


java.lang.NullPointerException
   at
org.eclipse.jface.dialogs.IconAndMessageDialog.getSWTImage(IconAndMessageDialog.java:225)

   at
org.eclipse.jface.dialogs.IconAndMessageDialog.getErrorImage(IconAndMessageDialog.java:172)

   at
org.eclipse.jface.dialogs.MessageDialog.<init>(MessageDialog.java:141)
   at
org.eclipse.jface.dialogs.MessageDialog.openError(MessageDialog.java:310)
   at
org.eclipse.jface.util.SafeRunnable.handleException(SafeRunnable.java:59)
   at
org.eclipse.core.internal.runtime.InternalPlatform.handleException(InternalPlatform.java:703)

   at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1023)

   at org.eclipse.core.runtime.Platform.run(Platform.java:757)
   at
org.eclipse.ui.part.WorkbenchPart.firePropertyChange(WorkbenchPart.java:121)

   at
horst.modeler.editors.BPELModelerEditor.setEditorModified(BPELModelerEditor.java:103)

   at
horst.modeler.editors.BPELModelerEditor.threadSafeSetEditorModified(BPELModelerEditor.java:96)

   at
horst.modeler.editors.BPELModelerEditor$1.graphNodesInserted(BPELModelerEditor.java:142)

   at
oracle.tip.tools.ide.common.graph.AbstractGraphModel.fireGraphNodesInserted(AbstractGraphModel.java:391)

   at
oracle.tip.tools.ide.common.graph.AbstractGraphModel.insertChildNode(AbstractGraphModel.java:132)

   at
oracle.tip.tools.ide.pm.bpelgraph.collaxalaf.BPELDNDDropHandler.handleDrop(BPELDNDDropHandler.java:202)

   at
oracle.tip.tools.ide.common.graph.DefaultGraphPaneDropTargetListener.routeToDropHandler(DefaultGraphPaneDropTargetListener.java:212)

   at
oracle.tip.tools.ide.common.graph.DefaultGraphPaneDropTargetListener.handleDrop(DefaultGraphPaneDropTargetListener.java:200)

   at
oracle.tip.tools.ide.pm.bpelgraph.collaxalaf.BPELGraphPaneDropTargetListener.handleDrop(BPELGraphPaneDropTargetListener.java:75)

   at
oracle.tip.tools.ide.common.graph.DefaultGraphPaneDropTargetListener.drop(DefaultGraphPaneDropTargetListener.java:260)

   at java.awt.dnd.DropTarget.drop(Unknown Source)
   at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(Unknown
Source)
   at sun.awt.dnd.SunDropTargetContextPeer.access$800(Unknown Source)
   at
sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(Unknown
Source)
   at
sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(Unknown
Source)
   at sun.awt.dnd.SunDropTargetEvent.dispatch(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processDropTargetEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)
_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eclipse beginner threading question...

Russ Rufer
You should only use the SWT event thread to manipulate your SWT widgets.
You can invoke a method on the event thread using either
Display.syncExec(Runnable runnable) or Display.asyncExec(Runnable
runnable) -- depending on whether you want your background thread to block.

 From your MultiPageEditorPart, you should be able to do something like:

Runnable runnable = new Runnable() {
    void run () {
       // activities you want to perform in the event thread
    }
};

getSite().getShell().getDisplay().asyncExec(runnable);


Hope that gets you unstuck.

- Russ


Horst Heistermann wrote:

> Hi,
>
> I am new to eclipse and I am having a problem with threads. I have
> created a MultiPageEditorPart
> editor. I have a background thread listening to model changes in my
> application. I am notified of these changes
> in a non -gui thread. I want to set MultiPageEditorPart as dirty
> whenever I receive a model change event.
> So I wrote a function like this
>
> public void setEditorModified() {
>       m_bModified = true;
>       if (!super.isDirty()) {
>           firePropertyChange(IEditorPart.PROP_DIRTY);
>       }
>   }
>
>
> This method crashes whenever I call it from the background thread.
> Below is the error stack. But it is a bit misleading. From the
> debugger, I can see the issue is with the thread I am calling
> firePropertyChange() from. Can anyone tell me what is the proper  way
> to update the dirty state from a background thread. Also, the
> background thread is not aware of the GUI components it only has a refer.


_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eclipse beginner threading question...

Horst Heistermann
Russ Rufer wrote:

> You should only use the SWT event thread to manipulate your SWT
> widgets. You can invoke a method on the event thread using either
> Display.syncExec(Runnable runnable) or Display.asyncExec(Runnable
> runnable) -- depending on whether you want your background thread to
> block.
>
> From your MultiPageEditorPart, you should be able to do something like:
>
> Runnable runnable = new Runnable() {
>    void run () {
>       // activities you want to perform in the event thread
>    }
> };
>
> getSite().getShell().getDisplay().asyncExec(runnable);
>
>
> Hope that gets you unstuck.
>
> - Russ
>
>
> Horst Heistermann wrote:
>
>> Hi,
>>
>> I am new to eclipse and I am having a problem with threads. I have
>> created a MultiPageEditorPart
>> editor. I have a background thread listening to model changes in my
>> application. I am notified of these changes
>> in a non -gui thread. I want to set MultiPageEditorPart as dirty
>> whenever I receive a model change event.
>> So I wrote a function like this
>>
>> public void setEditorModified() {
>>       m_bModified = true;
>>       if (!super.isDirty()) {
>>           firePropertyChange(IEditorPart.PROP_DIRTY);
>>       }
>>   }
>>
>>
>> This method crashes whenever I call it from the background thread.
>> Below is the error stack. But it is a bit misleading. From the
>> debugger, I can see the issue is with the thread I am calling
>> firePropertyChange() from. Can anyone tell me what is the proper  way
>> to update the dirty state from a background thread. Also, the
>> background thread is not aware of the GUI components it only has a
>> refer.
>
>
>
> _______________________________________________
> eclipse-dev mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or
> unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/eclipse-dev

Hi Russ,

  Thanks for your reply. But I am still stuck. My problem is that I  
have a listener and it gets notifed when a change has occurred in the
model. The listener is being notified
in a non gui thread. So when I am notified of the change it is on a non
ui thread. I then am trying to  call the line of code you have suggested

getSite().getShell().getDisplay().asyncExec(runnable);

from this non ui thread. It then crashes because evidently this is not
legal.  I guess what I am looking for is some utility or method that I
can say run this on the UI thread but
I can call the utility or method from this background thread. Something
like Swingutilities,.invokeLater in swing.

-- Horst
_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eclipse beginner threading question...

Russ Rufer

Hi Horst,

Display.asyncExec(Runnable runnable) should be analogous to
SwingUtilities.invokeLater(Runnable runnable). From the Display javadocs:

/**
 * Causes the <code>run()</code> method of the runnable to
 * be invoked by the user-interface thread at the next
 * reasonable opportunity. The caller of this method continues
 * to run in parallel, and is not notified when the
 * runnable has completed.

The purpose is the same as SwingUtilities.invokeLater(), to request that
the gui thread execute some code (the request being queued from another
thread). Maybe there's another cause for your exception?

- Russ

> Hi Russ,
>
> Thanks for your reply. But I am still stuck. My problem is that I  
> have a listener and it gets notifed when a change has occurred in the
> model. The listener is being notified
> in a non gui thread. So when I am notified of the change it is on a
> non ui thread. I then am trying to  call the line of code you have
> suggested
>
> getSite().getShell().getDisplay().asyncExec(runnable);
>
> from this non ui thread. It then crashes because evidently this is not
> legal.  I guess what I am looking for is some utility or method that I
> can say run this on the UI thread but
> I can call the utility or method from this background thread.
> Something like Swingutilities,.invokeLater in swing.
>
> -- Horst


_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eclipse beginner threading question...

Horst Heistermann
Russ Rufer wrote:

>
> Hi Horst,
>
> Display.asyncExec(Runnable runnable) should be analogous to
> SwingUtilities.invokeLater(Runnable runnable). From the Display javadocs:
>
> /**
> * Causes the <code>run()</code> method of the runnable to
> * be invoked by the user-interface thread at the next
> * reasonable opportunity. The caller of this method continues
> * to run in parallel, and is not notified when the
> * runnable has completed.
>
> The purpose is the same as SwingUtilities.invokeLater(), to request
> that the gui thread execute some code (the request being queued from
> another thread). Maybe there's another cause for your exception?
>
> - Russ
>
>> Hi Russ,
>>
>> Thanks for your reply. But I am still stuck. My problem is that I  
>> have a listener and it gets notifed when a change has occurred in the
>> model. The listener is being notified
>> in a non gui thread. So when I am notified of the change it is on a
>> non ui thread. I then am trying to  call the line of code you have
>> suggested
>>
>> getSite().getShell().getDisplay().asyncExec(runnable);
>>
>> from this non ui thread. It then crashes because evidently this is
>> not legal.  I guess what I am looking for is some utility or method
>> that I can say run this on the UI thread but
>> I can call the utility or method from this background thread.
>> Something like Swingutilities,.invokeLater in swing.
>>
>> -- Horst
>
>
>
> _______________________________________________
> eclipse-dev mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or
> unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/eclipse-dev

Hi Russ,,

I think I have found a solution. I have called this

Display.getDefault().asyncExec(new Runnable() {
            public void run() {
                setEditorModified();
            }
         });

before I tried this I tried to get access to the Display object thru the
IWorkBench like this

IWorkbench wb = PlatformUI.getWorkbench();
        IWorkbenchWindow w = wb.getActiveWorkbenchWindow();
        IWorkbenchPage p = w.getActivePage();

and these calls were failing.

Looks like Display.getDefault() will create the Display object which
solves the problem. But since I am new to eclipse, is this the proper
way to handle this?
_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eclipse beginner threading question...

Jared Burns
Obligatory message:
"This is a mailing list for the discussion of Eclipse wide development
issues - anything pertaining to the project as a whole. While this list
is open to the public, it is intended for discussions related to the
implementation of Eclipse itself. General questions about using Eclipse
should be directed to the appropriate Eclipse newsgroup."

http://eclipse.org/newsgroups/index.html
_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eclipse beginner threading question...

portal on behalf of Tod Creasey
In reply to this post by Horst Heistermann
Horst

This list is meant for news about the development of Eclipse - these sort
of questions are better asked in the newsgroups.

All calls to SWT must be done in the UI Thread. You can do this using
Display.asyncExec() Display,syncExec() or a UIJob.

Tod




Horst Heistermann <[hidden email]>
Sent by: [hidden email]
04/26/2005 04:19 PM
Please respond to
"General development mailing list of the Eclipse project."


To
[hidden email]
cc

Subject
[eclipse-dev] Eclipse beginner threading question...






Hi,

 I am new to eclipse and I am having a problem with threads. I have
created a MultiPageEditorPart
editor. I have a background thread listening to model changes in my
application. I am notified of these changes
in a non -gui thread. I want to set MultiPageEditorPart as dirty
whenever I receive a model change event.
So I wrote a function like this

public void setEditorModified() {
       m_bModified = true;
       if (!super.isDirty()) {
           firePropertyChange(IEditorPart.PROP_DIRTY);
       }
   }


This method crashes whenever I call it from the background thread. Below
is the error stack. But it is a bit misleading. From the debugger, I can
see the issue is with the thread I am calling firePropertyChange() from.
Can anyone tell me what is the proper  way to update the dirty state
from a background thread. Also, the background thread is not aware of
the GUI components it only has a refer.


java.lang.NullPointerException
   at
org.eclipse.jface.dialogs.IconAndMessageDialog.getSWTImage(IconAndMessageDialog.java:225)


   at
org.eclipse.jface.dialogs.IconAndMessageDialog.getErrorImage(IconAndMessageDialog.java:172)


   at
org.eclipse.jface.dialogs.MessageDialog.<init>(MessageDialog.java:141)
   at
org.eclipse.jface.dialogs.MessageDialog.openError(MessageDialog.java:310)
   at
org.eclipse.jface.util.SafeRunnable.handleException(SafeRunnable.java:59)
   at
org.eclipse.core.internal.runtime.InternalPlatform.handleException(InternalPlatform.java:703)


   at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1023)


   at org.eclipse.core.runtime.Platform.run(Platform.java:757)
   at
org.eclipse.ui.part.WorkbenchPart.firePropertyChange(WorkbenchPart.java:121)


   at
horst.modeler.editors.BPELModelerEditor.setEditorModified(BPELModelerEditor.java:103)


   at
horst.modeler.editors.BPELModelerEditor.threadSafeSetEditorModified(BPELModelerEditor.java:96)


   at
horst.modeler.editors.BPELModelerEditor$1.graphNodesInserted(BPELModelerEditor.java:142)


   at
oracle.tip.tools.ide.common.graph.AbstractGraphModel.fireGraphNodesInserted(AbstractGraphModel.java:391)


   at
oracle.tip.tools.ide.common.graph.AbstractGraphModel.insertChildNode(AbstractGraphModel.java:132)


   at
oracle.tip.tools.ide.pm.bpelgraph.collaxalaf.BPELDNDDropHandler.handleDrop(BPELDNDDropHandler.java:202)


   at
oracle.tip.tools.ide.common.graph.DefaultGraphPaneDropTargetListener.routeToDropHandler(DefaultGraphPaneDropTargetListener.java:212)


   at
oracle.tip.tools.ide.common.graph.DefaultGraphPaneDropTargetListener.handleDrop(DefaultGraphPaneDropTargetListener.java:200)


   at
oracle.tip.tools.ide.pm.bpelgraph.collaxalaf.BPELGraphPaneDropTargetListener.handleDrop(BPELGraphPaneDropTargetListener.java:75)


   at
oracle.tip.tools.ide.common.graph.DefaultGraphPaneDropTargetListener.drop(DefaultGraphPaneDropTargetListener.java:260)


   at java.awt.dnd.DropTarget.drop(Unknown Source)
   at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(Unknown
Source)
   at sun.awt.dnd.SunDropTargetContextPeer.access$800(Unknown Source)
   at
sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(Unknown

Source)
   at
sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(Unknown

Source)
   at sun.awt.dnd.SunDropTargetEvent.dispatch(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processDropTargetEvent(Unknown
Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)
_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev


_______________________________________________
eclipse-dev mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
Loading...