Join方法 09
1. join合并线程,待此线程执行完成后,在执行其它线程,其它线程阻塞
2.
package Runnable1;
//测试jion方法
public class TestJoin implements Runnable
{
package src;
class SimpleThread extends Thread
{
SimpleThread(String s)
{
super(s) ;
}
public void run()
{
for(int i=0;i<3;i++)
{
System.out.println(getName()+":"+i) ;
}
}
}
public class ThreadJion1
{
public static void main(String args[])
{
SimpleThread t1=new SimpleThread("first") ;
SimpleThread t2=new SimpleThread("second") ;
t1.start() ;
try
{
t1.join() ;
}
catch(InterruptedException e) {}
t2.start() ;
try
{
t2.join() ;
}
catch(InterruptedException e) {}
System.out.println("主线程运行!");
}
}
浙公网安备 33010602011771号