• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What needs to/doesn't need to be run on the EDT?

 
Ranch Hand
Posts: 64
4
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Due to the way AWT/Swing works, code that updates GUI elements should be run on the EDT. However, I'm not sure what doesn't need to be run on the EDT. For example, amongst other things, when initializing a window (like a JFrame, for instance), or setting its dimensions/location before it is first displayed/made visible, need it be run on the EDT? Should I just wrap everything in a SwingUtilities.invokeLater call?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it does need to be run on the EDT. The only thing snot to run on the EDT shou‍ld be long‑running tasks which are completely independent of the display. The threads for such tasks are often called worker threads. Have a look in the Java™ Tutorials.
By the way: calling invokeLater simply starts the EDT, so that bit sounds correct.
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:By the way: calling invokeLater simply starts the EDT, so that bit sounds correct.


To be pedantic, it's usually Component.setVisible() or Window.pack() that start the EDT. invokeLater() just adds tasks to the event queue.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting point.  What thread does the task started by invokeLater() execute on if the EDT hasn't been started by a method like: Component.setVisible() or Window.pack()?
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just speculating here, but I imagine nothing happens, and the task just remains in the queue until the EDT is started.
 
Norm Radder
Rancher
Posts: 5008
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When in doubt, write a test program:
This was in my non-GUI main for testing.  The output:


Running: java.exe -client -cp . TestCode22

This might well be displayed before the other message.
>>> main exiting <<<
Hello World on Thread[AWT-EventQueue-0,6,main]

0 error(s)

 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whelp, so much for speculation.
 
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic