• 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic