线程示例【1】
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");}}}?