是否有可能在任何情况下在 ThreadA 中获得“永远等待”的情况。我的意思是通知执行速度比b.sync.wait();
class ThreadA {
public static void main(String [] args) {
ThreadB b = new ThreadB();
b.start();
synchronized(b.sync)
{
try
{
System.out.println("Waiting for b to complete...");
b.sync.wait();
System.out.println("waiting done");
} catch (InterruptedException e) {}
}
}
}
class ThreadB extends Thread {
int total=0;
Integer sync = new Integer(1);
public void run() {
synchronized(sync)
{
sync.notify();
}
}
}