我怎么实现这样的功能?//伪码如下
Event A;methed A(){
  dosomething...
  wait(A);
}methed B(){
 A.setEvent();
}就是说,A方法被调用后会停在A事件上,当其他线程调用了B方法,A事件重置,A方法才返回.就像敲门一样,敲门后等待,直到有人开门才继续.

解决方案 »

  1.   

    我现在困惑的是怎么能够让A停止,再执行.就是那个Event的功能怎么实现?我在vc里面可以这样
    CEvent e;
    dosomething...
    WaitForSingleObject(e.m_hObject,100000);
    ...在需要继续执行的时候只要调用e.SetEvent就可以了。java中怎么实现呢?有没有CEvnet这种功能的类呢
      

  2.   

    Object类中的wait(), notify(), notifyAll()实现了类似的功能,自己去查一下文档吧
      

  3.   

    synchronized关键字控制互斥:Event A;synchronized methed A(){
      dosomething...
      wait(A);
    }synchronized methed B(){
     A.setEvent();
    }
    notify()和wait()控制同步
      

  4.   

    congliu() 这种方法对同一个对象不行吧,这样一个线程执行methodA之后等待,别的线呈还能去改变A的状态么