Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Swt &Thread
Swt &Thread [message #461858] Mon, 03 October 2005 16:04 Go to next message
Giovanni Marino is currently offline Giovanni MarinoFriend
Messages: 2
Registered: July 2009
Junior Member
I've made for test an SWT application based on database interaction.
When i press a button the application makes several update on DB.
If the operations number is small there is no problem, but if the number
id hight the application seems to be blocked.
I try to use the Async thread solution but the result is the same.
Is there a possibilty to run the update in background and use other
function of the application in the meanwhile?

Thanks for replay.

Giovanni Marino
Re: Swt &Thread [message #461859 is a reply to message #461858] Mon, 03 October 2005 17:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

That is probably because of a misunderstanding of how async works. It
does not start a new thread to run the runnable. It is actually just the
reverse. It queues up the runnable to be run on the UI thread. So you
must not use the asyncexec to do your db interaction. It would be the
other way around. You would create a thread to do the db interaction and
the db thread would do an asyncExec to update the UI.

Giovanni wrote:
> I've made for test an SWT application based on database interaction.
> When i press a button the application makes several update on DB.
> If the operations number is small there is no problem, but if the number
> id hight the application seems to be blocked.
> I try to use the Async thread solution but the result is the same.
> Is there a possibilty to run the update in background and use other
> function of the application in the meanwhile?
>
> Thanks for replay.
>
> Giovanni Marino
>
>

--
Thanks,
Rich Kulp
Re: Swt &Thread [message #461872 is a reply to message #461859] Tue, 04 October 2005 02:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: osipov.appliedtech.ru

So, what should be done then?
Re: Swt &Thread [message #461873 is a reply to message #461859] Tue, 04 October 2005 03:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lijuheng.21cn.com

in the swt doc:
Display Methods:
?? void asyncExec(Runnable runnable)
Gives non-user-interface threads the ability to invoke the protected
functions of the SWT widget classes. The user-interface thread performs the
code (invokes the run() method) of the runnable at its next "reasonable
opportunity." This function returns immediately.
void syncExec(Runnable runnable)
Like asyncExec(), this method gives non-userinterface threads the ability
to invoke the protected functions of the SWT widget classes. The
user-interface thread performs this code (invokes the run method) of
runnable at its next "reasonable opportunity." This function returns after
the run method of the Runnable object returns.

But they bouth return after the run method of the Runnable object
returns in my test example. I wish asyncExec() return immediately. How to
do?

Yours sincerely
Lijuheng

"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com>
??????:dhrp0f$4bi$2@news.eclipse.org...
> That is probably because of a misunderstanding of how async works. It
> does not start a new thread to run the runnable. It is actually just the
> reverse. It queues up the runnable to be run on the UI thread. So you
> must not use the asyncexec to do your db interaction. It would be the
> other way around. You would create a thread to do the db interaction and
> the db thread would do an asyncExec to update the UI.
>
> Giovanni wrote:
>> I've made for test an SWT application based on database interaction.
>> When i press a button the application makes several update on DB.
>> If the operations number is small there is no problem, but if the number
>> id hight the application seems to be blocked.
>> I try to use the Async thread solution but the result is the same.
>> Is there a possibilty to run the update in background and use other
>> function of the application in the meanwhile?
>>
>> Thanks for replay.
>>
>> Giovanni Marino
>>
>>
>
> --
> Thanks,
> Rich Kulp


  • Attachment: Class1.java
    (Size: 3.20KB, Downloaded 212 times)
Re: Swt &Thread [message #461875 is a reply to message #461859] Tue, 04 October 2005 09:05 Go to previous messageGo to next message
Giovanni Marino is currently offline Giovanni MarinoFriend
Messages: 2
Registered: July 2009
Junior Member
Ok, it works fine.

Thanks for your interest.

Giovanni Marino
Re: Swt &Thread [message #461908 is a reply to message #461873] Tue, 04 October 2005 13:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

asyncExec does return immediately. How did you determine that asyncExec
did not return immediately? Your example code gives no indication of
that kind of determination. To show that it does return immediately you
should put a sysout in your async selection listener both before and
after the call to the asyncExec, in addition to the calls within the
async exec runnable.


--
Thanks,
Rich Kulp
Re: Swt &Thread [message #462066 is a reply to message #461908] Wed, 05 October 2005 15:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lijuheng.21cn.com

OK, I see now.

I use these API inside event handlers, as it is already on the GUI thread,
so they behave the same.

Use these APIs only when need to manipulate a GUI on a different
thread than the thread that created the GUI.

Use asyncExec when don't need the GUI action performed immediately.
Use syncExec when do.


Thanks a lot
lijuehng


"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> д
Re: Swt &Thread [message #462077 is a reply to message #462066] Wed, 05 October 2005 19:13 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

syncExec on the UI thread doesn't buy much because it immediately turns
around and calls the runnable and then returns when the runnable is
done. You could of done that yourself.

asyncExec on the UI thread still works correctly by posting the runnable
off to the queue and returns immediately. If you call asyncExec on the
UI thread you are guarenteed that you will return from the asyncExec
call immediately and the runnable will be executed later on the UI
thread. This is sometimes a useful concept. There are certain things
that need to be done on the UI thread but can't be done at the
particular point in time due to some UI constraint. So you use asyncExec
to get it to run later.


--
Thanks,
Rich Kulp
Previous Topic:Check Style on Pocket PC
Next Topic:TableColumn hiding
Goto Forum:
  


Current Time: Thu Apr 25 11:23:33 GMT 2024

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

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

Back to the top