aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes invokeAndWait()/invokeLater() ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "invokeAndWait()/invokeLater() ??" Watch "invokeAndWait()/invokeLater() ??" New topic
Author

invokeAndWait()/invokeLater() ??

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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.


GenRocket - Experts at Building Test Data
Shyam Purkayastha
Ranch Hand

Joined: Jan 15, 2001
Posts: 57
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Thanks, that seems to work good.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invokeAndWait()/invokeLater() ??