为什么我无法reader
在此代码中收到通知:
public class ThreadMain {
public Thread reader;
private class SerialReader implements Runnable
{
public void run()
{
try
{
Thread.sleep(3000);
synchronized(this)
{
System.out.println("notifying");
notify();
}
Thread.sleep(3000);
} catch (Exception e){}
}
}
ThreadMain()
{
reader = (new Thread (new SerialReader()) );
}
public static void main(String [] args) {
ThreadMain d= new ThreadMain();
d.reader.start();
synchronized(d)
{
try
{
d.wait();
System.out.println("got notify");
} catch (Exception e) { System.out.println(e); }
}
}
}
我只有一行notifying
输出