Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Thread,SWT,ASYN,SYN problem
Thread,SWT,ASYN,SYN problem [message #456835] Fri, 10 June 2005 09:22 Go to next message
Eclipse UserFriend
Originally posted by: binjava.yahoo.com.cn

hi everybody...

who can tell me about difference of ASynExec and SynExec?


i create two threads by display.synexec

synexec(A)
synexec(B)

but B thread start still when A thread is finish.....
why?

A and B is ProgressBar....same...result..

i try asynexec.....
help...
Re: Thread,SWT,ASYN,SYN problem [message #456837 is a reply to message #456835] Fri, 10 June 2005 11:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hcs33.egon.gyaloglo.hu

Hi,

Both syncExec and asyncExec can be used to do something in the 'user
interface thread'. The main difference between them is explained in the
javadoc: the syncExec method causes your thread to wait for the specified
Runnable to finish but asyncExec is not: it returns immediately after it
'registers' the Runnable into the ui thread.

Example:
1. The specified Runnable (A) may or (most likely) may not be executed at
the time "A" is printed to the screen.
Display.asyncExec(A);
System.out.println("A");

2. The specified Runnable (A) is guaranteed to finish its work at the time
"A" is printed.
Display.syncExec(A);
System.out.println("A");

Note that - because the user interface thread is a single thread - it can
execute only one specified Runnable at a time. So your case is a normal
behaviour: first A is executed and then B either method you use.

HTH,
Regards,
Csaba

binjava wrote:
> hi everybody...
>
> who can tell me about difference of ASynExec and SynExec?
>
>
> i create two threads by display.synexec
>
> synexec(A)
> synexec(B)
>
> but B thread start still when A thread is finish.....
> why?
>
> A and B is ProgressBar....same...result..
>
> i try asynexec.....
> help...
Re: Thread,SWT,ASYN,SYN problem [message #456851 is a reply to message #456837] Fri, 10 June 2005 23:03 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 97
Registered: July 2009
Member
"Horv
Re: Thread,SWT,ASYN,SYN problem [message #456983 is a reply to message #456851] Mon, 13 June 2005 20:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I disagree. We get into far more problems using syncExec then asyncExec.
asycnExec means you can continue processing and eventually your runnable
will be executed. syncExec means you have to wait. There have been times
that the UI thread was waiting on something from the other thread and a
deadlocked occured. So it is usually better to use asyncExec.

>
> In addition to this, generally you do not need asyncExec().
> Unless you have specific need to use it, in most situation,
> you will need "syncExec()".
>

--
Thanks,
Rich Kulp
Re: Thread,SWT,ASYN,SYN problem [message #456999 is a reply to message #456983] Tue, 14 June 2005 09:51 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 97
Registered: July 2009
Member
"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
news:d8kq17$lc0$4@news.eclipse.org...
>I disagree. We get into far more problems using syncExec then asyncExec.
>asycnExec means you can continue processing and eventually your runnable
>will be executed. syncExec means you have to wait. There have been times
>that the UI thread was waiting on something from the other thread and a
>deadlocked occured. So it is usually better to use asyncExec.

Problem is that you normally need to use these while running
a heavy worker thread. Normally we need this for progressbars
or displaying progress information!

In pratice, you would like to use aync. But it doesn't do what you
would expect to occur, because background threads drain
CPU resources and async display thread seldom get control.
I found no cases that aync useful!

Regards.

>
>>
>> In addition to this, generally you do not need asyncExec().
>> Unless you have specific need to use it, in most situation,
>> you will need "syncExec()".
>>
>
> --
> Thanks,
> Rich Kulp
Re: Thread,SWT,ASYN,SYN problem [message #457002 is a reply to message #456999] Tue, 14 June 2005 13:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I haven't seen that. UI thread typically has a higher priority. In fact
to make sure that it does, we actually lowered the priority of our
worker thread slightly when it is started so that wouldn't hog the UI
thread. All of our usages, and some are quite heavy, don't have this
problem. But we just have different usage scenarios. One

Joe Smith wrote:
> "Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
> news:d8kq17$lc0$4@news.eclipse.org...
>
>>I disagree. We get into far more problems using syncExec then asyncExec.
>>asycnExec means you can continue processing and eventually your runnable
>>will be executed. syncExec means you have to wait. There have been times
>>that the UI thread was waiting on something from the other thread and a
>>deadlocked occured. So it is usually better to use asyncExec.
>
>
> Problem is that you normally need to use these while running
> a heavy worker thread. Normally we need this for progressbars
> or displaying progress information!
>
> In pratice, you would like to use aync. But it doesn't do what you
> would expect to occur, because background threads drain
> CPU resources and async display thread seldom get control.
> I found no cases that aync useful!
>
> Regards.
>
>
>>>In addition to this, generally you do not need asyncExec().
>>>Unless you have specific need to use it, in most situation,
>>>you will need "syncExec()".
>>>
>>
>>--
>>Thanks,
>>Rich Kulp
>
>
>

--
Thanks,
Rich Kulp
Re: Thread,SWT,ASYN,SYN problem [message #457014 is a reply to message #457002] Tue, 14 June 2005 22:25 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 97
Registered: July 2009
Member
"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
news:d8mlcn$jos$2@news.eclipse.org...
>I haven't seen that. UI thread typically has a higher priority. In fact to
>make sure that it does, we actually lowered the priority of our worker
>thread slightly when it is started so that wouldn't hog the UI thread. All
>of our usages, and some are quite heavy, don't have this problem. But we
>just have different usage scenarios. One

Which OS do you use?
The only usefulness of sync/asycExec is for worker threads alter UI.
On Windows, async doesn't get useful service. For example, progressbars
or display methods don't work properly when used with async.
But you got to control the rate of UI alterations carefully so that
speed doesn't get compromised!

In addition, if deadlock is an issue, then programming pratice or
SWT package should be re-evaluated.

Regards.


>
> Joe Smith wrote:
>> "Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> wrote in message
>> news:d8kq17$lc0$4@news.eclipse.org...
>>
>>>I disagree. We get into far more problems using syncExec then asyncExec.
>>>asycnExec means you can continue processing and eventually your runnable
>>>will be executed. syncExec means you have to wait. There have been times
>>>that the UI thread was waiting on something from the other thread and a
>>>deadlocked occured. So it is usually better to use asyncExec.
>>
>>
>> Problem is that you normally need to use these while running
>> a heavy worker thread. Normally we need this for progressbars
>> or displaying progress information!
>>
>> In pratice, you would like to use aync. But it doesn't do what you
>> would expect to occur, because background threads drain
>> CPU resources and async display thread seldom get control.
>> I found no cases that aync useful!
>>
>> Regards.
>>
>>
>>>>In addition to this, generally you do not need asyncExec().
>>>>Unless you have specific need to use it, in most situation,
>>>>you will need "syncExec()".
>>>>
>>>
>>>--
>>>Thanks,
>>>Rich Kulp
>>
>>
>>
>
> --
> Thanks,
> Rich Kulp
Re: Thread,SWT,ASYN,SYN problem [message #457015 is a reply to message #457014] Tue, 14 June 2005 22:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

We use windows all of the time, only one of our group uses Linux. We
don't see any problem with progress bars not updating when using
asyncexec. The only time I've seen that is when someone accidently
thought they were running their code in a separate thread from the UI
but they weren't. In that case the progress bar will not update until
they were completely done.

We use the Eclipse Job's API and we update the progress monitor from
there (the one passed into the job), and there is no problem with
updates to it. We also use async to update things like a swt Tree, and
again it works perfectly.

--
Thanks,
Rich Kulp
Re: Thread,SWT,ASYN,SYN problem [message #457039 is a reply to message #457015] Wed, 15 June 2005 17:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cezeugoh.hotmail.com

I have similar problems with display.syncExec(). I run it and it does
nothing and just hangs. Is this normal? Has anyone successfully tried out
SWT from an applet. I have been trying to get an OCX control working in
SWT. It works but when I wrap it around ORACLE's VBean implementation type
object (called from an applet) and make calls to display.close or
display.dispose i get the Invalid thread access message. When i try the
syncExec() route the program hangs.

Can someone please assist?

Elisha
Re: Thread,SWT,ASYN,SYN problem [message #457042 is a reply to message #457039] Wed, 15 June 2005 18:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Probably the problem is you are trying to do something to one UI thread
from another UI thread (SWT's thread versus AWT's thread). They are
probably dead-locking on each other. It would be better to use asyncExec
if all you wanted to do is to tell an SWT widget to dispose. It doesn't
need to occur immediately.

Elisha wrote:
> I have similar problems with display.syncExec(). I run it and it does
> nothing and just hangs. Is this normal? Has anyone successfully tried
> out SWT from an applet. I have been trying to get an OCX control working
> in SWT. It works but when I wrap it around ORACLE's VBean implementation
> type object (called from an applet) and make calls to display.close or
> display.dispose i get the Invalid thread access message. When i try the
> syncExec() route the program hangs.
>
> Can someone please assist?
>
> Elisha
>

--
Thanks,
Rich Kulp
Re: Thread,SWT,ASYN,SYN problem [message #457075 is a reply to message #457042] Thu, 16 June 2005 02:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cezeugoh.hotmail.com

Hi Richard,

What if I wanted the dispoe() to occur immediately what would i need to
do? Secondly is there a way of avoiding this sort of deadlock. You seem
close to the point as in to what the matter might be. An applet loads my
JavaBean which is an AWT extension and in this AWT extension, SWT display
class containing an OCX and enclosed by a simple java class is called and
opened. Its complex i know but do u get the picture I am trying to paint
and is this a feasible arrangement?

Kind Regards

Elisha
Re: Thread,SWT,ASYN,SYN problem [message #457079 is a reply to message #457075] Thu, 16 June 2005 14:18 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

I'm afraid I don't know your code well enough to give an answer. I don't
know what is going on the SWT UI thread at the time you do the syncExec.
You can go into debug mode and stop all of the threads and see what the
SWT UI thread is waiting for.
Elisha wrote:
> Hi Richard,
>
> What if I wanted the dispoe() to occur immediately what would i need to
> do? Secondly is there a way of avoiding this sort of deadlock. You seem
> close to the point as in to what the matter might be. An applet loads my
> JavaBean which is an AWT extension and in this AWT extension, SWT
> display class containing an OCX and enclosed by a simple java class is
> called and opened. Its complex i know but do u get the picture I am
> trying to paint and is this a feasible arrangement?
>
> Kind Regards
>
> Elisha
>

--
Thanks,
Rich Kulp
Previous Topic:More Dynamic Table Viewer Cell Modifiers?
Next Topic:How can the Browser detects that it has lost focus???
Goto Forum:
  


Current Time: Fri Mar 29 05:36:59 GMT 2024

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

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

Back to the top