【六袆 - Java】多线程打印倒计时Demo;多线程休眠;

代码

package com.erik.thread.stop;

/**
 * 模拟倒计时
 *
 * @author: xiaolh
 * @email: amixiao@qq.com
 * @createTime: 2021/6/6  10:44
 */
public class TestSleepThread01 {

    public static void main(String[] args) {
        try {
            turnDown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void turnDown() throws InterruptedException{
        int num = 10;
        while (true){
            Thread.sleep(1000);
            System.out.println(num--);
            if (num < 0){
                break;
            }
        }
    }
}

运行截图

 

 

 

 

posted @ 2022-04-26 00:53  你好,Alf  阅读(18)  评论(0编辑  收藏  举报