worker thread, UI thread and GEF [message #184518] |
Tue, 14 June 2005 08:30  |
Eclipse User |
|
|
|
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 #184655 is a reply to message #184624] |
Wed, 15 June 2005 02:58  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03285 seconds