Answer Posted / vivek ghavle
The Object class has three methods, wait(), notify(), and
notifyAll() that help threads
Communicate.
Suppose a mail processor thread has to keep checking if
there is any mail to process.
For example,
if one thread is a mail-delivery thread and one thread is a
mail-processor thread,
the mail-processor thread has to keep checking to see if
there's any mail to process.
Using the wait and notify mechanism, the mail-processor
thread could check for
mail, and if it doesn't find any it can say, "Hey, I'm not
going to waste my time
checking for mail every two seconds. I'm going to go hang
out, and when the mail
deliverer puts something in the mailbox, have him notify me
so I can go back to
runnable and do some work."
In other words, using wait() and notify() lets one thread
put itself into a "waiting room" until some other thread
notifies it that there's a reason to come back out.
wait(), notify(), and notifyAll() must be called from within
a synchronized
context! A thread can't invoke a wait or notify method on an
object unless it owns
that object's lock.
| Is This Answer Correct ? | 3 Yes | 1 No |
Post New Answer View All Answers
What is a class loader?
What is synchronization and why is it important?
Describe responsibilities of Activator?
What are the different class loaders used by jvm?
What is the difference between static and non-static with examples?
What is the relationship between local interfaces and container-managed relationships?
Do I have to use jsps with my application?
How are commas used in the intialization and iteration parts of a for statement?
Is there a guarantee of uniqueness for entity beans?
Difference between loadclass and class.forname?
What is the difference between java class and bean?
Which class is the immediate superclass of the menucomponent class?
Can I use javascript to submit a form?
What is a class loader? What are the different class loaders used by jvm?
Why do I get a duplicate name error when loading a jar file?