How two threads will communicate with each other?

Answer Posted / bindhu

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
and proceed.

Is This Answer Correct ?    57 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the purpose of introspection?

680


Explain the difference between object state and behavior?

570


What is the difference between the string and stringbuffer classes?

545


What is the form of storage space in java?

1744


Can you control when passivation occurs?

598






If your ui seems to freeze periodically, what might be a likely reason?

548


What are the steps to write p-to-p model application?

1963


Name three subclasses of the component class?

616


Can you give me a simple example of using the requiredif validator rule?

606


What are the different types of exception?

574


How are the elements of a cardlayout organized?

596


What must a class do to implement an interface?

586


Why use POJO when I can use hashmap

2047


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

649


Do we need to override service() method

1145