不是说notifyAll()是让所有挂起线程恢复的吗?下面代码怎么只恢复了其中t51的线程。。。
class A5 implements Runnable
{ int i=0;
String name;
public void run()
{ while(true)
{ i++;
System.out.println(name+"Z="+i);
if(i==5){
try{ 挂起线程A5();}
catch(Exception e){}
}
try{ Thread.sleep(1000);}
catch(Exception e){}
}
}
public synchronized void 挂起线程A5() throws InterruptedException
{ wait();
}
public synchronized void 恢复线程A5()
{ notifyAll();
}
}
public class Example15
{ public static void main(String args[])
{ int m=0;
A5 t51=new A5(); //线程A5的目标对象
t51.name="张一";
Thread thread=new Thread(t51);
thread.setName(t51.name);
A5 t52=new A5(); //线程A5的目标对象
t52.name="张二";
Thread thre=new Thread(t52);
thre.setName(t52.name);
thre.start();
thread.start();
while(true)
{ m++;
System.out.println("我是主线程m="+m);
if(m==10)
{ System.out.println("让全部线程继续工作");
try {
t51.恢复线程A5(); }
catch(Exception e){}
break;
}
try{ Thread.sleep(1000); }
catch(Exception e){}
}
}
}