Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27430

Re: The invokeLater loop

From Knute Johnson <eternal@knutejohnson.com>
Newsgroups comp.lang.java.programmer
Subject Re: The invokeLater loop
Date 2014-01-30 20:48 -0800
Organization A noiseless patient Spider
Message-ID <lcf9vh$up6$1@dont-email.me> (permalink)
References <invokeLater-loop-20130510204735@ram.dialup.fu-berlin.de> <bl0h10Fsp90U1@mid.uni-berlin.de>

Show all headers | View raw


On 1/30/2014 18:44, Stefan Ram wrote:
> I wrote on 2013-05-10:
>> I invented what I call the »invokeLater loop«:
>> class Object implements java.lang.Runnable
>> { int i = 0;
>> public void run()
>> { java.lang.System.out.println( i++ );
>> javax.swing.SwingUtilities.invokeLater( this ); }}
>> public class Main
>> { public static void main( final java.lang.String[] args )
>> { javax.swing.SwingUtilities.invokeLater( new Object() ); }}
>> What is it good for?
>
>    I the meantime, I have actually used the invokeLater loop in
>    an animation. From the functional requirements point of view,
>    it did work. But it was by orders of magnitude slower than
>    the same animation with a for loop. OTOH, the for loop blocks
>    the EDT (if you do not want to start another thread, that is).
>    So, I ended up using the for loop as an inner loop to do
>    some iterations fast and then using invokeLater to call the
>    next iterations of the for loop, so that the EDT gets some
>    leeway to do other things. So I got my animation with a
>    single thread of execution, running fast and the EDT still
>    being responsive.
>

That doesn't make a lot of sense to me.  Calling invokeLater schedules a 
task on the EDT.  If you want something to run consistently, calling 
invokeAndWait would make more sense.  But given modern computers have 
multiple processors with multiple cores, it really makes more sense to 
use a separate thread and do active rendering off the EDT or to use 
invokeAndWait and keep your rendering times short.  Both will allow time 
for the EDT to process other things and give you fast and smooth animation.

-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

The invokeLater loop ram@zedat.fu-berlin.de (Stefan Ram) - 2013-05-10 18:54 +0000
  Re: The invokeLater loop Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-10 12:18 -0700
    Re: The invokeLater loop Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-10 14:26 -0700
    Re: The invokeLater loop Joerg Meier <joergmmeier@arcor.de> - 2013-05-10 23:28 +0200
    Re: The invokeLater loop Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-10 17:39 -0400
    Re: The invokeLater loop Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-10 23:50 +0200
  Re: The invokeLater loop markspace <markspace@nospam.nospam> - 2013-05-10 14:51 -0700
  Re: The invokeLater loop Silvio <silvio@internet.com> - 2013-05-11 00:26 +0200
    Re: The invokeLater loop Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-10 15:52 -0700
  Re: The invokeLater loop Roedy Green <see_website@mindprod.com.invalid> - 2013-05-10 23:27 -0700
    Re: The invokeLater loop "Qu0ll" <Qu0llSixFour@gmail.com> - 2013-05-12 19:44 +1000
  Re: The invokeLater loop Knute Johnson <eternal@knutejohnson.com> - 2014-01-30 20:48 -0800

csiph-web