创建一个线程
对A 线程使用join方法
主线程会等带A线程结束
public class JoinTest {
public static void main(String[] args) throws InterruptedException{
AThread a=new AThread();
a.start();
//没有join print结果是0
System.out.println(AThread.count);
}
}
class AThread extends Thread{
public static int count=0;
public void run(){
count=5;
}
}
/**
* Created by root on 16-3-20.
*/
public class JoinTest {
public static void main(String[] args) throws InterruptedException{
AThread a=new AThread();
a.start();
a.join();
System.out.println(AThread.count);
}
}
class AThread extends Thread{
public static int count=0;
public void run(){
count=5;
}
}
加入join 结果为5