package com.thread;
/**
* 2010-10-26
* 通过实现Runnable接口实现线程
* @author Administrator
*
*/
public class Demo3 {
public static void main(String[] args) {
Monkey monkey=new Monkey();
//monkey.run();
Thread t=new Thread(monkey);
t.start();
t.start(); //编译不会出错,但运行会出错,一个线程类只能启动一次
}
}
class Monkey implements Runnable{
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){
break;
}
}
}
}