sleep()和wait()区别
import lombok.*;
/*
o.wait();释放锁
...
Thread.sleep(6000);
6004
...
* */
public class T {
@SneakyThrows
public static void main(String[] args) {
Object o = new Object();
new Thread(() -> {
synchronized (o) {
try {
long begin = System.currentTimeMillis();
Thread.sleep(6000);
// o.wait();
System.out.println(System.currentTimeMillis() - begin);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(() -> {
synchronized (o) {
System.out.println("...");
}
}).start();
}
}