• 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

invokeAndWait()/invokeLater() ??

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my application I have a JTree that I am going to update every xxx minutes. So I made this class:

Now I have a class that extends JPanel and in that class I build my tree. After I build my tree I then want to go ahead and start the Runnable class so that the tree will update every xxx minutes.
So I do this:

I have also tried

The problem is that this Runnable starts running, but I never get returned to the GUI. Everything in the GUI just hangs while the Thread runs.
Any ideas?

BTW - This is a JApplet in case that makes a difference.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shold not use invokelater().Since invokelater() executes the thread in the event dispatched thread and as your thread runs in an infinite loop it will never end and your application will hang.
Why dont you run it as a seperate thread alltogether.
new Thread(Runable/*your Runnable class*/).start();
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, that seems to work good.
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is right to do the updating in the AWT-main-thread. so I'd suppose it's safer to do this:

when you catch the interrupted exception you should call "Thread.currentThread().interrupt()" - unless the current thread is the AWT-main-thread, of course. otherwise the thread does not die.
this polling thread will most probably never be interrupted, but for data retrieval in a gui, it is important.
see this very good article on stopping threads:
http://www.javaspecialists.co.za/archive/Issue056.html
Chantal
[ November 25, 2002: Message edited by: Chantal Ackermann ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic