J
John Resler
I know I'm being very general about a question that is very specific but
that's the way it goes. In the development of an application that is
multi-threaded, deadlock is always a problem and I'm having a problem with
the app I'm working on now. I got back into the books and solved part of the
problem but now I'm viewing some material and handling IPC (Inter-Thread
Communications in this case) and I'm curious about the language in "The Java
Programming Language, 3rd edition", Arnold, Gosling, Holmes.
In the threads chapter, there is a discussion of using the wait() call for
notification of completion by another thread. The statement says wait()
should always be placed in a loop rather than an if condition, eg:
synchronized void doWhenCondition() {
while(!condition)
wait();
// Do what must be done when condition is true.
}
My question is that, if I have a thread that waits, or a thread that sleeps,
they both can be notified by notify() or notifyAll(). In short, is it really
necessary to place a wait() call in a busy wait state, rather than a sleep()
state? Any opinions are appreciated.
-John Resler
WDMC
Wichita, Kansas
(e-mail address removed)
that's the way it goes. In the development of an application that is
multi-threaded, deadlock is always a problem and I'm having a problem with
the app I'm working on now. I got back into the books and solved part of the
problem but now I'm viewing some material and handling IPC (Inter-Thread
Communications in this case) and I'm curious about the language in "The Java
Programming Language, 3rd edition", Arnold, Gosling, Holmes.
In the threads chapter, there is a discussion of using the wait() call for
notification of completion by another thread. The statement says wait()
should always be placed in a loop rather than an if condition, eg:
synchronized void doWhenCondition() {
while(!condition)
wait();
// Do what must be done when condition is true.
}
My question is that, if I have a thread that waits, or a thread that sleeps,
they both can be notified by notify() or notifyAll(). In short, is it really
necessary to place a wait() call in a busy wait state, rather than a sleep()
state? Any opinions are appreciated.
-John Resler
WDMC
Wichita, Kansas
(e-mail address removed)