Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > The invokeLater loop

Reply
Thread Tools

The invokeLater loop

 
 
Roedy Green
Guest
Posts: n/a
 
      05-11-2013
On 10 May 2013 18:54:38 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

> Maybe it provides a way to loop while still allowing
> Swing events to be processed in parallel? (So you do not
> always have to spawn another thread besides the EDT.)


You want Swing manipulation to run on the EDT and non Swing stuff to
run on some other threads. invokeLater lets you put stuff on the
Swing thread from some non-Swing thread. If you are already on the
Swing thread, you don't need it.
--
Roedy Green Canadian Mind Products http://mindprod.com
Nothing is so good as it seems beforehand.
~ George Eliot (born: 1819-11-22 died: 1880-12-22 at age: 61) (Mary Ann Evans)
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      01-31-2014
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.

 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      01-31-2014
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows 8 - so bad it's hastening the death of the PC? ~misfit~ NZ Computing 18 04-15-2013 04:15 AM
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Can someone use invokeLater() to call a public method from a JPanel? ***C.Steamer*** Java 39 10-29-2004 02:00 PM
SwingUtilities.invokeLater Ike Java 2 10-08-2003 08:47 PM
InvokeLater Mohit Gupta ASP .Net 0 07-11-2003 07:34 AM



Advertisments