public class HelloWorld {
public static void main(String[] args) {
//创建线程要执行的任务
Runnable r1 = new MyRunnable();
//创建线程
Thread t1 = new Thread(r1);
t1.start();
}
}
class MyRunnable implements Runnable{
public void run(){
for(int i=0;i<10;i++){
System.out.println("HelloWorld");
try {
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
写一个线程每隔10秒输出一次“HelloWorld”,输出10次后退出
最新推荐文章于 2024-07-14 02:58:51 发布
