1. 程式人生 > >每隔10秒鐘打印一個“Helloworld”

每隔10秒鐘打印一個“Helloworld”

rac extend out dimp sim exce new row mat

/**
 * 每隔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”