0

is this procedure going to execute in separate thread?

class Counter extends Thread {
    public void run() {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                for(int i=0;isCounting;i++) {
                    try {Thread.currentThread().sleep(100);} 
                    catch (InterruptedException e) {e.printStackTrace();}
                    setTitle(""+i);
                }
            }
        });
    }
}

it is a part of class which extends JFrame. now, if i start an instance of this class somewhere in the constructor of JFrame extending class, will it run in the separate thread, or in the EDT? because i tried it, and obviously it runs in EDT because the program stuck...

nicks
  • 2,161
  • 8
  • 49
  • 101
  • Refer to http://stackoverflow.com/questions/3541373/should-we-use-eventqueue-invokelater-for-any-gui-update-in-java-desktop-applicati and this http://www.javapractices.com/topic/TopicAction.do?Id=153 – Favonius Apr 25 '11 at 15:50

1 Answers1

1

You are telling Java to run that on the EDT when you use EventQueue.invokeLater.

For more on this, please see this tutorial: Concurrency in Swing

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373