开发者

what will happen if i call wait method on object outside of synchronisation block? [duplicate]

T开发者_JAVA技巧his question already has answers here: Closed 11 years ago.

Possible Duplicate:

Why wait should always be in synchronized block

What will happen if I call wait() and notify(), notifyAll() method outside of synchronization ? Does it has any effect ?

example

Class Test(){
 Test(){

I know I am writing empty try catch

   try{
      wait(); 
      notify();
      notifyAll();
   }catch (Exception ex)
  }
}


You get an IllegalMonitorStateException,

IllegalMonitorStateException - if the current thread is not the owner of the object's monitor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜