开发者

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

开发者 https://www.devze.com 2023-03-12 03:34 出处:网络
T开发者_JAVA技巧his question already has answers here: Closed 11 years ago. Possible Duplicate: Why wait should always be in synchronized block
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

精彩评论

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