A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 後天__牛永志 黑马帝   /  2011-11-17 14:34  /  1734 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

   public synchronized void set(String name,String sex){
                                          if(flag){
                                               try{this.wait();}catch(Exception e){}//1
                                           }else{
                                                   this.name=name;
                                                    this.sex=sex;
                                          }
                                                 flag=true;
                                                 this.notifyAll();//2
                       }
                       public synchronized void get(){
                                       if(!flag){
                                            try{this.wait();}catch(Exception e){};//3
                                         }else{
                                              System.out.println(Thread.currentThread().getName()+"  "+name+"------->"+sex);
                                         }
                                             flag=false;
                                              this.notifyAll();//4
                                        }
                        }


2和4处处的notifyAll能唤醒哪的等待线程
2能唤醒3处的等待线程吗,4能唤醒3处的等待线程吗

1 个回复

倒序浏览
4唤醒3?...........................................................
想唤也唤不醒了,你flag都改变了,如果能唤醒3   那同步就么有意思了。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马