/**
* 2018.8.30
* 作者:小孟鱼
* 功能:演示如何通过Runnable来开发线程
*
*/
package com.xianchen;
public class Xianchen2 {
public static void main(String[] args) {
Dog dog=new Dog();
//启动线程方法1
//dog.run();
//启动线程方法2
Thread t=new Thread(dog);
t.start();
}
}
class Dog implements Runnable
{
public void run()
{
int times=0;
//while(true)是一个死循环
while(true)
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
times++;
System.out.println("Hello world"+times);
if(times==10)
{
break;
}
}
}
}