Thread类中的sleep方法

package com.chunzhi;
/*
    public static void sleep(long millis):使当前正在执行的线程以指定的毫秒数暂停(暂时停止执行);
    毫秒结束后将会继续执行
 */
public class Test03sleep {
    public static void main(String[] args) {
        // 模拟一个秒表
        for (int i = 1; i <= 60 ; i++) {
            System.out.println(i);
            // 使用Thread类的sleep方法让程序睡眠1秒钟 
            // sleep方法本身有异常,这里用了try...catch处理了此异常
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

 

posted @ 2020-11-11 22:51  春志  阅读(955)  评论(0)    收藏  举报