Wait和Sleep的区别
先说结果: wait 方法会释放对象锁,但 sleep 方法不会。
代码实现:
wait:
package com.baidu.demo01;
public class WaitDemo {
private static Object locker = new Object();
public static void main(String[] args) throws InterruptedException {
WaitDemo waitDemo = new WaitDemo();
new Thread(()->{
try {
waitDemo.dowait();
} catch (InterruptedException e) {
e.printStackTrace();
}