java 线程的堵塞

//线程的阻塞
//

//线程
class xc1 implements Runnable{
    public void run(){
        for(int i=1;i<=30;i++){
            System.out.println(Thread.currentThread().getName()+"线程___"+i);
        }
    }
}


public class Index{
    public static void main(String[] args){
        

        //线程1
        xc1 xc1 = new xc1();
        Thread xc1_Thread = new Thread(xc1);
        xc1_Thread.start();    //执行线程
        
       
        try{
            //线程的阻塞
            //线程堵塞的方法 join
            //需要加异常处理
            //先执行这个线程,其他的所有线程暂停,等这个执行完毕后,在重新分配其他线程执行
            xc1_Thread.join();
        }
        catch(Exception e){
            
        }
        
        
        //线程2
        xc1 xc2 = new xc1();
        Thread xc2_Thread = new Thread(xc2);
        xc2_Thread.start();    //执行线程
 

    }
}
原文地址:https://www.cnblogs.com/phpyangbo/p/5964478.html