Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronized Method or Code  RSS feed

 
Sameera Abeysinghe
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods call for the wait (), notify(), notifyall(), must be placed in side a synchronized block Is this always true ? Explain�

We can put these methods inside a non synchronized method or code without compile �time errors.
Can you explain the logic behind this?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All those methods do need to be inside appropriate synchronisation. However, the lock could be obtained in some other piece of code, which then calls the method containing the wait(), notify() or whatever. Therefore, the compiler can't enforce this.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!