Answers were Sorted based on User's Feedback
Two threads can communicate with each other using
the wait() and notify() , notifyAl() methods. wait()
method tells the thread to wait until another threads
calls notify() method.
The wait() method causes the current thread to wait
(possibly forever) until another thread notifies it of a
condition change. We use wait() in conjunction with notify
() or notifyAll() to coordinate the activities of multiple
threads using the same resources.
The notifyAll() method notifies all the threads waiting on
the monitor held by the current thread and wakes them up.
Typically, one of the waiting threads will grab the monitor
|Is This Answer Correct ?||57 Yes||8 No|
Answer / vivek ghavle
The Object class has three methods, wait(), notify(), and
notifyAll() that help threads
Suppose a mail processor thread has to keep checking if
there is any mail to process.
if one thread is a mail-delivery thread and one thread is a
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
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|
important features of java which differenciate it from c++
What is the immediate superclass of the applet class?
What is the difference between a stub and a skeleton?
how to create Calculator GUI using Gridbaglayout as like as Window Calculator??????????? (Open calculator Go-->Run-->type calc-->Enter)
Define the remote object implementation?
whats is mean by connectionpooling
what is difference between object state and behaviour?
How to get an image from db2 database plz help as soon as possible
what is the use of Object Factories?
What are the different class loaders used by jvm?
Explain what is orm?
What is the difference between the session.update() method and the session.lock() method?