vj <> wrote:
> Thomas suggested that the wait() call must be encapsulated in a loop
> that checks for wakeup conditions. I am requesting a sample that shows
> its usage over wait() thats not called from a loop.
Very precisely, the program must be written so that it behaves correctly
for a wait function that returns earlier the the next notify or
notifyAll. To put it in simple terms, imagine that Object.wait() were
implemented like this:
public void wait() throws InterruptedException
{
magicallyReleaseLock();
// don't really wait at all!
magicallyReacquireLock();
}
Would your code still work, except for any performance requirements? If
not, then your code is already broken.
Practically speaking, this always involves writing a loop. Just for
completeness sake, I'll point out that in theory you could actually use
recursion instead... but it would be a heck of a complicated mess.
I don't doubt that you saw broken sample code. Unfortunately, it
happens rather frequently.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation