|
|
|
Re: about swt 's thread . [message #451636 is a reply to message #451616] |
Thu, 03 March 2005 19:02 |
Eclipse User |
|
|
|
Originally posted by: bob.objfac.com
Essentially you're saying the two ways are equivalent and the first way
is simpler. True, but if computing the data took a minute or more,
wouldn't he be better off running the compute in a separate thread in
the background, then using asyncExec to update the widget? A minute is
an awfully long time to hang the UI thread.
Bob
Veronika Irvine wrote:
> The first way is better.
>
> The second way still runs in the UI thread and if the data computation takes
> a minute or so, you will end up blocking the UI thread and the application
> will be unresponsive (hung) until it completes. Display.asyncExec runs when
> the event loop is idle but it may not be idle for very long.
>
>
> "bbskill" <bbkills@tom.com> wrote in message
> news:d06sqn$d69$1@www.eclipse.org...
>
>>if a long run Thread update a widget many times,then which
>>code is better?
>>first: updateRunnable = new Runnable() {
>>public void run() {
>>//update a widget; }
>>}
>>new Thread() {
>>public void run() {
>>for(int i = 0 ; i< manytimes; i++) {
>>//compute the data ,costs some time
>>display.syncExec(updateRunnable);
>>//compute some data,costs some time
>>}
>>}
>>}.start();
>>
>>second:
>>display.asyncExec(new Runnable() {
>>public void run() {
>>for(int i = 0 ; i< manytimes; i++) {
>>//compute the data ,costs some time
>>//update a widget; //compute some data,costs some time
>>}
>>}
>>});
>>Thank you for your help !
>
>
>
|
|
|
Re: about swt 's thread . [message #451639 is a reply to message #451636] |
Thu, 03 March 2005 19:29 |
Veronika Irvine Messages: 1272 Registered: July 2009 |
Senior Member |
|
|
Maybe my words were not very clear. The two ways are not the same at all.
The second one hangs up the UI thread if it runs for any significant length
of time. The second way starts the work when the event loop is idle but
will block new events until it completes and therefore is bad. The first
way executes only the minimum amount of work in the UI thread (updating the
UI) and therefore does not or hang the GUI - that is why it is better.
"Bob Foster" <bob@objfac.com> wrote in message
news:42275F3D.2090705@objfac.com...
> Essentially you're saying the two ways are equivalent and the first way is
> simpler. True, but if computing the data took a minute or more, wouldn't
> he be better off running the compute in a separate thread in the
> background, then using asyncExec to update the widget? A minute is an
> awfully long time to hang the UI thread.
>
> Bob
>
> Veronika Irvine wrote:
>> The first way is better.
>>
>> The second way still runs in the UI thread and if the data computation
>> takes a minute or so, you will end up blocking the UI thread and the
>> application will be unresponsive (hung) until it completes.
>> Display.asyncExec runs when the event loop is idle but it may not be idle
>> for very long.
>>
>>
>> "bbskill" <bbkills@tom.com> wrote in message
>> news:d06sqn$d69$1@www.eclipse.org...
>>
>>>if a long run Thread update a widget many times,then which
>>>code is better?
>>>first: updateRunnable = new Runnable() {
>>>public void run() {
>>>//update a widget; }
>>>}
>>>new Thread() {
>>>public void run() {
>>>for(int i = 0 ; i< manytimes; i++) {
>>>//compute the data ,costs some time
>>>display.syncExec(updateRunnable);
>>>//compute some data,costs some time
>>>}
>>>}
>>>}.start();
>>>
>>>second:
>>>display.asyncExec(new Runnable() {
>>>public void run() {
>>>for(int i = 0 ; i< manytimes; i++) {
>>>//compute the data ,costs some time
>>>//update a widget; //compute some data,costs some time
>>>}
>>>}
>>>});
>>>Thank you for your help !
>>
>>
|
|
|
Re: about swt 's thread . [message #451649 is a reply to message #451639] |
Fri, 04 March 2005 06:09 |
Eclipse User |
|
|
|
Originally posted by: bob.objfac.com
My humble apologies. I misread the first example. It's exactly what I
suggested. Feeling pretty foolish, but thanks for your kind reply.
Bob
Veronika Irvine wrote:
> Maybe my words were not very clear. The two ways are not the same at all.
> The second one hangs up the UI thread if it runs for any significant length
> of time. The second way starts the work when the event loop is idle but
> will block new events until it completes and therefore is bad. The first
> way executes only the minimum amount of work in the UI thread (updating the
> UI) and therefore does not or hang the GUI - that is why it is better.
>
> "Bob Foster" <bob@objfac.com> wrote in message
> news:42275F3D.2090705@objfac.com...
>
>>Essentially you're saying the two ways are equivalent and the first way is
>>simpler. True, but if computing the data took a minute or more, wouldn't
>>he be better off running the compute in a separate thread in the
>>background, then using asyncExec to update the widget? A minute is an
>>awfully long time to hang the UI thread.
>>
>>Bob
>>
>>Veronika Irvine wrote:
>>
>>>The first way is better.
>>>
>>>The second way still runs in the UI thread and if the data computation
>>>takes a minute or so, you will end up blocking the UI thread and the
>>>application will be unresponsive (hung) until it completes.
>>>Display.asyncExec runs when the event loop is idle but it may not be idle
>>>for very long.
>>>
>>>
>>>"bbskill" <bbkills@tom.com> wrote in message
>>>news:d06sqn$d69$1@www.eclipse.org...
>>>
>>>
>>>>if a long run Thread update a widget many times,then which
>>>>code is better?
>>>>first: updateRunnable = new Runnable() {
>>>>public void run() {
>>>>//update a widget; }
>>>>}
>>>>new Thread() {
>>>>public void run() {
>>>>for(int i = 0 ; i< manytimes; i++) {
>>>>//compute the data ,costs some time
>>>>display.syncExec(updateRunnable);
>>>>//compute some data,costs some time
>>>>}
>>>>}
>>>>}.start();
>>>>
>>>>second:
>>>>display.asyncExec(new Runnable() {
>>>>public void run() {
>>>>for(int i = 0 ; i< manytimes; i++) {
>>>>//compute the data ,costs some time
>>>>//update a widget; //compute some data,costs some time
>>>>}
>>>>}
>>>>});
>>>>Thank you for your help !
>>>
>>>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03561 seconds