Multithread RAP application, ui contribution [message #122484] |
Tue, 24 February 2009 12:51  |
Eclipse User |
|
|
|
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 09:21  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.07740 seconds