INTER THREAD
COMMUNICATION
WHY IT IS REQUIRED ???
There are situations when one thread keeps on checking for
some condition repeatedly, once that condition satisfies the
thread moves ahead with its appropriate action. This situation is
known as POLLING.
This is basically a wastage of CPU time which is undesirable so,
to avoid polling, java has an elegant inter thread communication
mechanism.
WHAT IS IT ??
•Allowing synchronized threads to communicate
with each other.
•Cooperation is a mechanism in which a thread
is paused running in its critical section and
another thread is allowed to enter (or lock) in
the same critical section to be executed.
EXAMPLE :
HOW INTER THREAD COMMUNICATION IS
ACHIEVED ???
It is implemented by following methods
of Object class:
wait()
notify()
notifyAll()
UNDERSTANDING THE PROCESS OF INTER-
THREAD COMMUNICATION
WAIT() METHOD
NOTIFY() METHOD
Syntax :
public final void notify()
NOTIFYALL() METHOD
Syntax :
public final void notifyAll()
Why wait(), notify() and
notifyAll() methods are defined
in Object class not Thread
class ?
DIFFERENCE BETWEEN WAIT AND SLEEP ?
THANK YOU

Inter - thread communication

  • 1.
  • 2.
    WHY IT ISREQUIRED ??? There are situations when one thread keeps on checking for some condition repeatedly, once that condition satisfies the thread moves ahead with its appropriate action. This situation is known as POLLING. This is basically a wastage of CPU time which is undesirable so, to avoid polling, java has an elegant inter thread communication mechanism.
  • 3.
    WHAT IS IT?? •Allowing synchronized threads to communicate with each other. •Cooperation is a mechanism in which a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed.
  • 4.
  • 6.
    HOW INTER THREADCOMMUNICATION IS ACHIEVED ??? It is implemented by following methods of Object class: wait() notify() notifyAll()
  • 7.
    UNDERSTANDING THE PROCESSOF INTER- THREAD COMMUNICATION
  • 8.
  • 9.
  • 10.
    NOTIFYALL() METHOD Syntax : publicfinal void notifyAll()
  • 11.
    Why wait(), notify()and notifyAll() methods are defined in Object class not Thread class ?
  • 12.
  • 15.