top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

In Java when should the method invokeLater() be used?

+2 votes
58 views
posted Sep 5, 2013 by Arvind Singh

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote
 
Best answer

Method invokeLater(Runnable doRun) causes doRun.run() to be executed asynchronously on the AWT event dispatching thread. This will happen after all pending AWT events have been processed.
This method should be used when an application thread needs to update the GUI. In the following example the invokeLater call queues the Runnable object pickHighBetaStock on the event dispatching thread and then prints a message.

Runnable pickHighBetaStock = new Runnable() {
    public void run() {
        System.out.println("High beta Stockpicked by  " + Thread.currentThread());
    }
};
SwingUtilities.invokeLater(pickHighBetaStock);
 System.out.println("This might well be displayed before the other message. if Event-dispatcher thread is busy");
answer Sep 5, 2013 by Satyabrata Mahapatra

Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...