while or if

多线程 wait  && notifyAll 模式实现时,如果 锁中有判断,对共享对象有curd 操作时,有可能出现异常

即,判断 条件 这个时候关键字有 if 改为while 即可

   while(flag)
            try{
               this.wait();
            }catch(Exception e){}
       //t1(放弃资格)  t2(获取资格)
        this.name = name+"--"+count++;

  

while循环语句,可以执行多次,if是条件语句,只是单次执行。

while(表达式) 语句组; 计算表达式,若为真,执行语句,并重复该过程,直到为假时,执行下一条语句。

posted @ 2018-04-09 20:17  谢幕ゾ华丽  阅读(127)  评论(0编辑  收藏  举报