/**
* @author ZhangShaoWen
* @time 2013-12-25
* @function 线程的使用
*/
package com.test2;
public class XianC {
public static void main(String[] args) {
Cat cat = new Cat();
//启动线程
cat.start();
Dog dog = new Dog();
//启动线程的令一种方式
Thread t = new Thread(dog);
t.start();
}
}
class Cat extends Thread{
//重写run方法
public void run(){
int times = 0;//记录次数
while(true){
try {//休眠一秒
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Hello World!");
times ++;
if(times == 3){
break;
}
}
}
}
class Dog implements Runnable{
public void run(){
System.out.println("Dog!");
}
}