谁帮我解释下一个关于JAVA的问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 08:12:31
public class SimpleRunnable implements Runnable{

/**
* @param args
*/
private boolean active;
private String mask;
private static int count=0;
SimpleRunnable(){
this('t');
}
SimpleRunnable(char maskChar){
setActive(true);
mask=" "+(count++)+maskChar;

}
public void setActive(boolean active){
this.active=active;
}
public boolean isActive(){
return active;
}
public String toString(){
return "线程名称为"+Thread.currentThread().getName()+":"+mask;
}
public void run(){
int i=0;
while(isActive()){
System.out.println(this);
try{
Thread.currentThread().sleep(50);
}catch(Exception e){
e.printStackTrace();
}
i++;
if(i==10){
setActive(false);
}
}

}
public static void main(String[] ar

//Runnable 是接口 SimpleRunnable 继承了此接口 Thread 中间的参数就是其Runnable 、、Runnable 接口实现了 run()方法
线程启动必须要start()的方法才能开始

不明白就问吧。。线程那多看看就行

debug 就能看见过程