我在t2.start(); 前开始可了t2.join();此时主函数应该等待t2执行完,但是t2还没开起,主线程已经等待,岂不是死循环了。但运行结果是三个线程交替。为什么啊
class demo implements Runnable
{
public void run()
{
for (int x =0;x<70 ;x++ )
{
System.out.println(Thread.currentThread().getName()+"..."+x);
}
}
}
class day1209
{
public static void main(String[] args) throws Exception
{
demo d =new demo();
Thread t1 = new Thread(d);
Thread t2 = new Thread(d);
t1.start();
t2.join();// 此处没用啊
t2.start();
for (int x =0;x<60 ;x++ )
{
System.out.println("main"+x);
}
}
}
|