想问一下t1.start();t2.start();t1.join()在如下代码的执行顺序
class JoinDemo
{
public static void main(String[] args) throws InterruptedException
{
Demo d=new Demo();
Thread t1=new Thread(d);
Thread t2=new Thread(d);
t1.start();
t2.start();
t1.join() ; // t1 t2交替执行,直到t1执行完毕 ?
// 先 t1 t2交替执行,在调用t1.join()后只执行t1?
for (int x=0;x<50 ;x++ )
{System.out.println("hello world");
}
}
}
class Demo implements Runnable
{
public void run()
{
for (int x=0;x<60 ;x++ )
{
System.out.println(Thread.currentThread().getName()+"---run"+x);
}
}
}
|