12 休眠线程

发布时间 2023-09-05 22:49:26作者: 被占用的小海海

package ThreadDemo;

// 1. 模拟网络延迟:放大问题发生的情况
// 2. 模拟倒计时
public class Test12_Sleep {
    public static void main(String[] args) throws InterruptedException {
        tenDown();
    }

    public static void tenDown() throws InterruptedException {
        int n=10;
        while (true){
            Thread.sleep(1000);
            System.out.print(n--+" ");
            if (n<=0) break;
        }
    }
}