Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » worker thread, UI thread and GEF
worker thread, UI thread and GEF [message #184518] Tue, 14 June 2005 12:30 Go to next message
Eclipse UserFriend
Originally posted by: michel.hassenforder.uha.fr

Hello,

I have a strange problem, here the situation:

I have created a Job which creates repeatedly a new element which is
added to the model. The edit part catches the changes and forwards the
changes to the figure (as usual). After some walk in the figure
hierarchy the framework decides to invalidate the figure and a
DeferedUpdateManager is called. It decides to call the queueWork method
which crashes nicely with a nullPointerException. Lookup the source, I
find that it is due to the fact that the queueWork method asks the
Display to find the display associated to the current thread. It seems
assumed that the current thread IS a UI thread. As my thread is a
“worker” one it is not associated to the UI and the response is null.
And the story ends with the nullPointerException.

My question is: how can I change a model in a non UI (Worker) thread and
of course the UI (part/figure) reflects the change (as usual)?

Thanks in advance
Re: worker thread, UI thread and GEF [message #184624 is a reply to message #184518] Wed, 15 June 2005 01:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

You can't. Draw2d requires such changes to be made on the UI thread. The
fix is that your worker thread should invoke the model change part in
Display.asyncExec() (or syncExec if you need to wait for that task to finish
before proceeding). I am not sure how the jobs framework is set up, but be
careful about deadlocks.

"Michel Hassenforder" <michel.hassenforder@uha.fr> wrote in message
news:d8mile$gnb$1@news.eclipse.org...
> Hello,
>
> I have a strange problem, here the situation:
>
> I have created a Job which creates repeatedly a new element which is
> added to the model. The edit part catches the changes and forwards the
> changes to the figure (as usual). After some walk in the figure
> hierarchy the framework decides to invalidate the figure and a
> DeferedUpdateManager is called. It decides to call the queueWork method
> which crashes nicely with a nullPointerException. Lookup the source, I
> find that it is due to the fact that the queueWork method asks the
> Display to find the display associated to the current thread. It seems
> assumed that the current thread IS a UI thread. As my thread is a
>
Re: worker thread, UI thread and GEF [message #184640 is a reply to message #184624] Wed, 15 June 2005 06:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michel.hassenforder.uha.fr

Thank you for the reply.
It was what I haved guessed.
I will look around the Display.asyncExec() to see if it can solve the
problem.


Pratik Shah a écrit :

> You can't. Draw2d requires such changes to be made on the UI thread. The
> fix is that your worker thread should invoke the model change part in
> Display.asyncExec() (or syncExec if you need to wait for that task to finish
> before proceeding). I am not sure how the jobs framework is set up, but be
> careful about deadlocks.
>
> "Michel Hassenforder" <michel.hassenforder@uha.fr> wrote in message
> news:d8mile$gnb$1@news.eclipse.org...
>
>>Hello,
>>
>>I have a strange problem, here the situation:
>>
>>I have created a Job which creates repeatedly a new element which is
>>added to the model. The edit part catches the changes and forwards the
>>changes to the figure (as usual). After some walk in the figure
>>hierarchy the framework decides to invalidate the figure and a
>>DeferedUpdateManager is called. It decides to call the queueWork method
>>which crashes nicely with a nullPointerException. Lookup the source, I
>>find that it is due to the fact that the queueWork method asks the
>>Display to find the display associated to the current thread. It seems
>>assumed that the current thread IS a UI thread. As my thread is a
>>“worker” one it is not associated to the UI and the response is null.
>>And the story ends with the nullPointerException.
>>
>>My question is: how can I change a model in a non UI (Worker) thread and
>>of course the UI (part/figure) reflects the change (as usual)?
>>
>>Thanks in advance
>
>
>
Re: worker thread, UI thread and GEF [message #184655 is a reply to message #184624] Wed, 15 June 2005 06:58 Go to previous message
Steve Jones is currently offline Steve JonesFriend
Messages: 95
Registered: July 2009
Member
Pratik Shah wrote:

> You can't. Draw2d requires such changes to be made on the UI thread. The
> fix is that your worker thread should invoke the model change part in
> Display.asyncExec() (or syncExec if you need to wait for that task to
> finish
> before proceeding). I am not sure how the jobs framework is set up, but
> be careful about deadlocks.
>
> "Michel Hassenforder" <michel.hassenforder@uha.fr> wrote in message
> news:d8mile$gnb$1@news.eclipse.org...
>> Hello,
>>
>> I have a strange problem, here the situation:
>>
>> I have created a Job which creates repeatedly a new element which is
>> added to the model. The edit part catches the changes and forwards the
>> changes to the figure (as usual). After some walk in the figure
>> hierarchy the framework decides to invalidate the figure and a
>> DeferedUpdateManager is called. It decides to call the queueWork method
>> which crashes nicely with a nullPointerException. Lookup the source, I
>> find that it is due to the fact that the queueWork method asks the
>> Display to find the display associated to the current thread. It seems
>> assumed that the current thread IS a UI thread. As my thread is a
>> “worker” one it is not associated to the UI and the response is null.
>> And the story ends with the nullPointerException.
>>
>> My question is: how can I change a model in a non UI (Worker) thread and
>> of course the UI (part/figure) reflects the change (as usual)?
>>
>> Thanks in advance

I think you need to add something like this in the notification path between
the worker thread and the editparts notification processing:

if (Display.getCurrent() == null) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
epNotifyChanged(notification);
}
});
}
else {
epNotifyChanged(notification);
}


Steve.
Previous Topic:Image interaction
Next Topic:ConnectionEditPart
Goto Forum:
  


Current Time: Thu Dec 12 18:16:19 GMT 2024

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

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

Back to the top