Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Multithread RAP application, ui contribution
Multithread RAP application, ui contribution [message #122484] Tue, 24 February 2009 17:51 Go to next message
Lukas Dziadkowiec is currently offline Lukas DziadkowiecFriend
Messages: 12
Registered: July 2009
Junior Member
Hi,
I have problem contributing to UI from different thread that UIThread.
I'm developing RAP application where user can run special programs in
tabs. User selects program from list and clicks run, than new Thread is
started. This new thread creates new tab and creates some gui within it.
Then it is suspended by calling wait() and waits for user interaction.
Problem is that ui calls in this thread is not reflected until this thread
ends, just wait() is no good enough. I tried something like that I found
on this page.
http://www.devx.com/webdev/Article/36101/1954

Example
RunProgramAction() {
run() {
UICallBack.activate("notifierId");
Thread programLabelThread = new Thread(new
ProgramLabelThread(composite));
notifierThread.setDaemon(true);
notifierThread.start();
}
}

public class ProgramLabelThread implements Runnable {
public synchronized void run() {
int c = 0;
while (c++ < 5) {
composite.getDisplay().asyncExec(new Runnable(){
public void run() {
Label label = new Label(composite, SWT.NORMAL);
label.setText("LabelXXX: ");
}
});
System.out.println(c);
try {
Thread.sleep(500);
} catch (InterruptedException e) {}
}
composite.getDisplay().asyncExec(new Runnable() {
public void run() {
UICallBack.deactivate("notifierId");
}
});
try {
wait();
}
}

Well it seems like Display is not flushed and refreshed until I do window
resizing in browser, but the concept should be OK. Is there any pattern
how to do multithreading application when several threads could contribute
into their part of gui and can be suspended and waked while GUI itself
will redraw ?

In fact real program will be more complex and will end by calling
int waitForUserInteraction() {
wait();
return keyCode;
}

Thank you for any hints.
Re: Multithread RAP application, ui contribution [message #123250 is a reply to message #122484] Thu, 26 February 2009 17:07 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
the call to UICallback-deactivate() is probably too early. To verify
this, could you remove the call at all?

HTH
Rüdiger

Lukas Dziadkowiec wrote:
> Hi,
> I have problem contributing to UI from different thread that UIThread.
> I'm developing RAP application where user can run special programs in
> tabs. User selects program from list and clicks run, than new Thread is
> started. This new thread creates new tab and creates some gui within it.
> Then it is suspended by calling wait() and waits for user interaction.
> Problem is that ui calls in this thread is not reflected until this
> thread ends, just wait() is no good enough. I tried something like that
> I found on this page.
> http://www.devx.com/webdev/Article/36101/1954
>
> Example
> RunProgramAction() {
> run() {
> UICallBack.activate("notifierId");
> Thread programLabelThread = new Thread(new
> ProgramLabelThread(composite));
> notifierThread.setDaemon(true);
> notifierThread.start();
> }
> }
>
> public class ProgramLabelThread implements Runnable {
> public synchronized void run() {
> int c = 0;
> while (c++ < 5) {
> composite.getDisplay().asyncExec(new Runnable(){
> public void run() {
> Label label = new Label(composite, SWT.NORMAL);
> label.setText("LabelXXX: ");
> }
> });
> System.out.println(c);
> try {
> Thread.sleep(500);
> } catch (InterruptedException e) {}
> }
> composite.getDisplay().asyncExec(new Runnable() {
> public void run() {
> UICallBack.deactivate("notifierId");
> }
> });
> try {
> wait();
> }
> }
>
> Well it seems like Display is not flushed and refreshed until I do
> window resizing in browser, but the concept should be OK. Is there any
> pattern how to do multithreading application when several threads could
> contribute into their part of gui and can be suspended and waked while
> GUI itself will redraw ?
>
> In fact real program will be more complex and will end by calling
> int waitForUserInteraction() {
> wait();
> return keyCode;
> }
>
> Thank you for any hints.
>
Re: Multithread RAP application, ui contribution [message #123329 is a reply to message #123250] Fri, 27 February 2009 14:21 Go to previous message
Lukas Dziadkowiec is currently offline Lukas DziadkowiecFriend
Messages: 12
Registered: July 2009
Junior Member
Hi,
your right, I have already pushed things forward. I switched do sync calls
and it looks fine. In my application RAP program interface listens for
outside calls and builds UI according to this calls. But since this is
done in another thread I have to make sync UI call for each request like
display.syncExec(createFieldRunnable);. This is very ineffective. I have
to rewrite interface that it will cache all UI as proxy and flushes it in
one sync / async call at the end.
Previous Topic:Read data from custom widget.
Next Topic:Change perspective
Goto Forum:
  


Current Time: Tue Apr 16 03:58:17 GMT 2024

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

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

Back to the top