大家看看多线程的理解
public class consumer extends Thread{int time;
String str;
int count;
public consumer(int time,String str){
this.time=time;
this.str=str;
count=0;
}
public void run(){
while(true){ //此种循环好好记住
try{
System.out.println("consumer name:"+str);
Thread.sleep(time);
}catch(Exception e){
e.printStackTrace();
}
if(count++>4) break;
}
}
static public void main(String[]args){//看到没有不仅只有public static
consumer a=new consumer(1000,"a");//1000相当于1S么
a.start();
consumer b=new consumer(2000,"b");
b.start();
consumer c=new consumer(3000,"c");
c.start();
}
}
//结果不明白
consumer name:a
consumer name:c
consumer name:b
consumer name:a
consumer name:b
consumer name:a
consumer name:c
consumer name:b
consumer name:a
consumer name:c
consumer name:b
consumer name:b
consumer name:c
consumer name:c
谁能解释下线程!我就这块觉得难。