开发者

java eventqueue

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...


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜