系统休眠Sleep

每个对象都有一把锁,sleep不会释放锁

package Sleep;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TestSleep {


public static void main(String[] args) throws InterruptedException {
//模拟倒计时
// tenDown();

//打印当前系统时间
Date date = new Date(System.currentTimeMillis());
while(true){
Thread.sleep(1000);
System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
date = new Date(System.currentTimeMillis());
}
}

public static void tenDown() throws InterruptedException {
int num = 10;
while (true){
Thread.sleep(1000);
System.out.println(num--);
if (num <= 0)
break;
}
}
}
posted @ 2021-04-07 15:22  术树  阅读(70)  评论(0)    收藏  举报