写一个线程,每隔10秒钟标准输出到屏幕上一个”hello world” , 打印10次以后退出。
package cn.com.cloud.test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ThreadTest {
public static void main(String[] args) throws InterruptedException {
ThreadImp threadImp = new ThreadImp();
Thread thread1 = new Thread(threadImp);
thread1.start();
}
}
class ThreadImp extends Thread{
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("StartThread-"+(i+1)+":"+new SimpleDateFormat("yyyy/MM/dd hh:mm:ss:Ms").format(new Date()));
System.out.println("hello world");
try {
sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}