每隔10秒钟打印一个“Helloworld”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了每隔10秒钟打印一个“Helloworld”相关的知识,希望对你有一定的参考价值。

/**
 * 每隔10秒钟打印一个“Helloworld”
 */
public class Test03 {

    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秒钟打印一个“Helloworld”的主要内容,如果未能解决你的问题,请参考以下文章

使用相同的三行代码打印多行

shell每隔一秒钟就记录下netstat状态

VBA Macro On Timer样式每隔几秒钟运行代码,即120秒

检查鼠标按钮是不是按下按钮/图片并每隔几秒钟继续执行一个功能直到按下按钮?

63使用Timer类来实现定时任务

网络协议及tcp协议详解(超清楚的大图,难得还解释了会话层和表示层。服务端有一个保活计时器,时间通常是设置为2小时。发送一个探测报文段,以后每隔75秒钟发送一次,一连发送10个探测报文)