Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How two threads will communicate with each other?

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


Please Help Members By Posting Answers For Below Questions

Why use a datasource when you can directly specify a connection details? (in a J2EE application)

4275


What do you know about seam?

1058


What’s jboss jbpm?

1035


What is the purpose of the finally clause of a try-catch-finally statement?

1036


What you mean by COM and DCOM?

1065


Why doesn’t the focus feature on the tag work in every circumstance?

1109


A user of a web application sees a jsessionid argument in the URL whenever a resource is accessed. What does this mean? a. The form must have the field jsessionid b. URL rewriting is used as the session method c. Cookies are used for managing sessions

2246


Is jvm a overhead?

1103


How would you create a button with rounded edges?

1153


What do you need to set-up a cluster with jboss?

1077


How to deploy Jar, War files in J2EE?

2697


Describe responsibilities of Activator?

2277


What is aop(assepct oriented programing)?

1066


Can I import same package/class twice? Will the jvm load the package twice at runtime?

1153


How substring() method of string class create memory leaks?

1046