public static void main(String[] args) {
Object obj = new Object();
new Thread(){
@Override
public void run() {
while (true){
synchronized (obj){
System.out.println("等待老板做包子");
System.out.println(Thread.currentThread().getName());
try {
obj.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("包子做好了");
System.out.println("_______________");
}
}
}
}.start();
new Thread(){
@Override
public void run() {
while (true){
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (obj){
System.out.println(Thread.currentThread().getName());
System.out.println("包子开始做了");
obj.notify();
}
}
}
}.start();
}
为什么总是wait()线程抢到cpu的执行权而不是notify()所在的线程?求解