Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Worker thread question
Worker thread question [message #259542] Thu, 08 July 2004 09:38 Go to next message
Eclipse UserFriend
Originally posted by: weberjn.yahoo.com

The situation: RCP application needs to fill a dialogue from a database
via hibernate. Getting the data needs about two seconds, in this time
there is no gui update and the gui looks very hackly.

So, I want to have the data loaded by a second thread.
One option were that this thread fills the data into the gui with

display.syncExec(
new Runnable() {
public void run(){
label.setText(text);
}
}
);

( http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/faq.html#uithread)

But what is the main thread to do in the meantime?

It should be blocked, so the user cannot do anything (i.e. leave the
dialog while the data is still loading), but also it should update the
gui. How can this be done?


parallel
begin worker thread
load data
copy data into gui
set ready semaphore
end worker thread
begin gui thread
while not (ready semaphore)
update gui
end worker thread
end parallel

I have no idea how to transform the gui thread pseudo code into real code,
i.e. how to have eclipse update the gui and at the same time block user
input.

Thanks for links and hints,
Juergen
Re: Worker thread question [message #259759 is a reply to message #259542] Thu, 08 July 2004 15:48 Go to previous message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

To keep the UI alive (but blocked) while running a process in another
thread, use the IProgressService:

PlatformUI.getWorkbench().getProgressService().busyCursorWhi le(runnable).
From within that runnable, you can post updates to the UI using
asyncExec or syncExec.

However, if you are already within the context of a modal dialog, you
may not need to block the user in this way. You can just create a
background Job (org.eclipse.core.runtime.jobs.Job), that will fetch the
data from the server and post periodic updates to the UI (for example
using a UIJob). This allows you to keep the UI alive and interactive
while the background work goes on.
--

Juergen Weber wrote:
> The situation: RCP application needs to fill a dialogue from a database
> via hibernate. Getting the data needs about two seconds, in this time
> there is no gui update and the gui looks very hackly.
>
> So, I want to have the data loaded by a second thread.
> One option were that this thread fills the data into the gui with
>
> display.syncExec(
> new Runnable() {
> public void run(){
> label.setText(text);
> }
> }
> );
>
> ( http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/faq.html#uithread)
>
> But what is the main thread to do in the meantime?
>
> It should be blocked, so the user cannot do anything (i.e. leave the
> dialog while the data is still loading), but also it should update the
> gui. How can this be done?
>
>
> parallel
> begin worker thread
> load data
> copy data into gui
> set ready semaphore
> end worker thread
> begin gui thread
> while not (ready semaphore)
> update gui
> end worker thread
> end parallel
>
> I have no idea how to transform the gui thread pseudo code into real code,
> i.e. how to have eclipse update the gui and at the same time block user
> input.
>
> Thanks for links and hints,
> Juergen
>
>
Previous Topic:eclipse current CVS (after 3.0 final)
Next Topic:Java files not getting compiled. Eclipse 3.0
Goto Forum:
  


Current Time: Sat Jul 27 13:23:05 GMT 2024

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

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

Back to the top