package com.thread;
/**
* 2010-10-26
* 继承Thread实现线程
* 每秒打印hello world,当打印10次时退出打印
* @author Administrator
*
*/
public class Demo2 {
public static void main(String args[]){
Dog dog=new Dog();
dog.start();
}
}
class Dog extends Thread{
public void run(){
int time=0;
while(true){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("hello,world");
time++;
if(time==10){
//退出,跳出while循环,线程也就死亡
break;
}
}
}
}