Java多线程--join关键字

创建一个线程
对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

posted @ 2016-03-20 14:47  Salaku  阅读(334)  评论(0编辑  收藏  举报