每隔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”的主要内容,如果未能解决你的问题,请参考以下文章