本帖最后由 马伟奇 于 2011-12-18 12:16 编辑
我用IDE直接执行和用DEBUG模式执行结果不一样,同样的代码。求解决
public class ThreadDemo4 implements Runnable {
@Override
public void run(){
for(int i = 0 ; i<5;i++){
System.out.println(Thread.currentThread().getName());
}
}
public static void main(String[] args) {
ThreadDemo4 td = new ThreadDemo4();
Thread t = new Thread(td,"线程");
t.start();
for(int i = 0; i<5;i++){
if(i>2){
try {
t.join();
} catch (Exception e) {
// TODO: handle exception
}
}
System.out.println("main线程运行"+i);
}
}
}
|