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
精彩评论