dcsimg
Why does 'notify' have to be 'synchronized' ?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sol_myr
Posted On:   Tuesday, May 17, 2005 01:06 AM

Why do they required that "Object.notify" be called only while holding the lock, namely: synchronized(obj){ // must be here, otherwise exception is thrown obj.notify(); } I'm been asking around for *ages* ... I realize that logically, it's *likely* that whoever called "notify", did so right after performing changes to some shared data. In which case they're likely to be holding the lock anyway. But that's not a good enough reason... the fact it's logically likely, doesn't explain why they decided to *mandate* it on a technical level... Thanks :)    More>>

Why do they required that "Object.notify" be called only while holding the lock, namely:

			
synchronized(obj){ // must be here, otherwise exception is thrown
obj.notify();
}


I'm been asking around for *ages* ...




I realize that logically, it's *likely* that whoever called "notify", did so right after performing changes to some shared data. In which case they're likely to be holding the lock anyway. But that's not a good enough reason... the fact it's logically likely, doesn't explain why they decided to *mandate* it on a technical level...


Thanks :)    <<Less
About | Sitemap | Contact