写一个线程,每隔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();
}
}
}
}
此程序创建了一个线程,该线程每隔10秒在屏幕上打印一次Hello World,共打印10次后退出。
287

被折叠的 条评论
为什么被折叠?



