例13_1 本例用于演示线程终止
// 本例用于演示线程终止
class E13_1
{
public static void main(String args[])
{
A a=new A();
Thread thread=new Thread(a);
thread.setName("zhang san");
thread.start();
}
}
class A implements Runnable
{
int number=0;
boolean stop=false;
boolean getStop()
{
return stop;
}
public void run()
{
while(!stop)
{
number++;
System.out.println(Thread.currentThread().getName()+"的number="+number);
if(number==3){
stop=true;
}
try{ Thread.sleep(1000);}
catch(Exception e){}
}
}
}