每个对象都有1个锁,sleep不会释放锁
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestThreadSleep2 {
public static void main(String[] args) {
Date date = new Date(System.currentTimeMillis());
boolean flag = true;
while (flag) {
System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
date = new Date(System.currentTimeMillis());
}
}
}
学习视频:狂神说java
网友评论