9.2.编写Java程序模拟烧水泡茶最优工序

package threaddddd;


class xiShuiHu extends Thread{
	private Integer i;
	xiShuiHu(Integer ii){
		this.i=ii;
	}
	
	public synchronized void run() {
        int ww=0;
		while(++ww<=1) {
			++i;
			int w=0;
			while(++w<=1000) ;
			System.out.println("xiShuiHu--"+i);
			
		}
		  
		
	}
	
	
	
}


class shaoShui implements Runnable{
	private Integer i; 
	public int ww=0;
	shaoShui(Integer ii){
		this.i=ii;
	}
	
	public void run() {
       
		while(++ww<=15) {
			++i;
			int w=0;
			while(++w<=1000) ;
			System.out.println("shaoShui--"+i);
			
		}
		  
	}

	
}



class xiXiNa implements Runnable{//包含了洗茶壶,洗茶杯,拿茶叶
	private Integer i;      
	public int ww=0;  
	xiXiNa(Integer ii){
		this.i=ii;
	}
	
	public void run() {
   
		while(++ww<=4) {
            ++i;
			int w=0;
			while(++w<=1000) ;
			System.out.println("xiXiNa--"+i);
            }
		  
		
	}

	
}






class paoCha implements Runnable{
	private Integer i;
	paoCha(Integer ii){
		this.i=ii;
	}

	public void run() {
        int m=0;
		while(++m<=10) {
			++i;
			int w=0;
			while(++w<=1000) ;
			System.out.println("paoCha--"+i);
			
		}
		  
		
	}

}






public class zhu {


	public static void main(String[] args) {

		Thread xsh =new xiShuiHu(0);
		xsh.start();
		try {
		xsh.join();}
		catch(InterruptedException it){}
		
		
		shaoShui r=new shaoShui(0);
		Thread sh=new Thread(r);
		
	
		
		xiXiNa r1=new xiXiNa(0);
		Thread xxn=new Thread(r1);



		
		sh.start();	
		

		xxn.start();


		try {
		sh.join();}
		catch(InterruptedException it){}
		
		try {
		xxn.join();}
		catch(InterruptedException it){}
	
		

		paoCha r2=new paoCha(0);
		Thread pc=new Thread(r2);		
		
		pc.start();

		

	}

}

汗颜!!!

a.join() 方法是让调用a的线程x停止运行(只会使x线程停下来,其他线程不受影响),直到a线程完成后,x线程继续执行

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值