- public class Test {
- public static void main(String[] args) {
- Rq r=new Rq();
- Tq t=new Tq(r);
- Thread t1=new Thread(t);
- t1.start();
- for(int x=0;x<10;x++){
- System.out.print(x);
- if(x==1){
- try {
- t1.join(100);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if(x==8){
- r.notifyAll();
- }
- }
- }
-
-
- }
-
- }
- class Tq implements Runnable{
- private Rq r;
- Tq(Rq r){
- this.r=r;
- }
- public void run(){
- r.show();
- }
- }
- class Rq{
-
- synchronized void show(){
- for(int x=0;x<100;x++){
- System.out.println(Thread.currentThread()+"x="+x);
- if(x==90){
- try {
- this.wait();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
- }
复制代码 我要改什么,才能让show方法内,剩余的x=91到100打印出来?为什么加了r.notifyAll();也没唤醒呢????
|
|