首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

线程示范【2】

2012-12-25 
线程示例【2】package com.thread/** * 2010-10-26 * 继承Thread实现线程 * 每秒打印hello world,当打印10

线程示例【2】

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;}}}}
?

热点排行