package com.thread;
/**
* 2010-10-26
* 通过继承Thread实现线程
* 每秒循环打印hello world
*/
public class Demo1 {
public static void main(String[] args) {
Cat cat=new Cat();
//启动线程,让run函数运行
cat.start();
}
}
class Cat extends Thread{
//重写run函数
public void run(){
while(true){
try {
//休眠1秒
//1000代表1000毫秒
//sleep会让线程进入到阻塞状态(Blocked),并且释放资源
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("hello,world");
}
}
}
线程示例【1】
最新推荐文章于 2011-11-29 16:21:16 发布