当程序执行到t1.join(); 时,有没有可能是:此时正在执行的进程是t2,然后t1.join(); 让t2放弃了cpu。当t1执行完了,t2才会执行。
class Demo implements Runnable
{
public void run()
{
for(int x=0; x<70; x++)
{
System.out.println(Thread.currentThread().toString()+"....."+x);
}
}
}
class JoinDemo
{
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.start();
t1.join();
for(int x=0; x<80; x++)
{
System.out.println("main....."+x);
}
System.out.println("main over");
}
} |
|