think in java在线程这一章有一习题:
Create two Thread subclasses, one with a run( ) that starts up and then calls wait( ). The other class’s run( ) should capture the reference of the first Thread object. Its run( ) should call notifyAll( ) for the first thread after some number of seconds have passed so that first thread can print a message.我写了程序如下:
class Thread1 extends Thread{

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
//super.run();
try{
wait();
}catch(InterruptedException e){
e.printStackTrace();
}
System.out.println("Thread1 go out of wait");
}}
class Thread2 extends Thread{
private Thread1 td1;
Thread2(Thread1 t){
td1=t;
}
/**
 * @see java.lang.Runnable#run()
 */
public void run() {
//super.run();
try{
sleep(400);
}catch(InterruptedException e){
e.printStackTrace();
}
synchronized(td1) {
td1.notify();
}
}
}
public class Exercise08 { public static void main(String[] args) {
new Thread2(new Thread1());
}
}
可执行后,什么输出也没有,这是怎么回事?