public class Run {
public static void main(String[] args) {
try{
RunThreas runThreas=new RunThreas();
runThreas.start();
//Thread.sleep(2000);
runThreas.setIsrunning(false);
System.out.println("已经赋值为false");
}catch (Exception e){
e.printStackTrace();
}
}
}
class RunThreas extends Thread{
private boolean isrunning=true;
public boolean isRunning(){
return isrunning;
}
public void setIsrunning(boolean isrunning){
System.out.println(Thread.currentThread().getName()+"set");
this.isrunning=isrunning;
}
@Override
public void run() {
super.run();
System.out.println(Thread.currentThread().getName()+"run");
System.out.println("进入run");
while(isrunning){
System.out.println("i am running");
}
System.out.println("线程被停止了");
}
}
setIsrunnning()
方法属于Runthread
,所以我认为它应该由Runthread
的instanse调用,但实际上它是由Thread“main”调用的。我想知道这是为什么?