public class Lock {
public static void main(String[] args) throws InterruptedException {
Object obj = new Object();
new Thread(new Runnable() {
@Override
public void run() {
synchronized (obj) {
try {
System.out.println("等待前");
obj.wait(); // obj
System.out.println("等待后");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
synchronized (obj) {
System.out.println("唤醒前");
obj.notify();
System.out.println("唤醒后");
}
}
}).start();
}
}