This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait(), notify() in non synchronized method

 
P Ventura
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
what happens if wait()/notify() is present in a non synchronized code?
An exception is thrown?
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. The system will throw an IllegalMonitorStateException if it invokes wait/notify/notifyAll in a non-synchronized context. Try it out and see for yourself.

In addition, not just any synchronized context will do. This code will also throw an IllegalMonitorStateException:

[ November 05, 2007: Message edited by: Kelvin Lim ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic