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线程继续执行